亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使我的編碼計算器中的輸入框居中?

如何使我的編碼計算器中的輸入框居中?

慕容森 2023-02-22 15:59:21
我正在嘗試使用 Python 3.7.2 在 Tkinter 中編寫一個基本的計算器。沒什么特別的,但我一直遇到同樣的問題:看在耶穌的份上,我無法移動輸入欄,使其位于所有輸入按鈕/第一行之上。我嘗試將它放在不同的列中或使用其他版本的代碼geometry,但絕對沒有任何效果。我還在(德語)Q&A-Site Gutefrage上提出了問題,但似乎沒有很多程序員/答案有點不清楚。關于如何做到這一點的任何想法?這是我的代碼(WIP):from random import *from math import *def insert_1():    text.insert(END, "1")def insert_2():    text.insert(END, "2")def insert_3():    text.insert(END, "3")def insert_4():    text.insert(END, "4")def insert_5():    text.insert(END, "5")def insert_6():    text.insert(END, "6")def insert_7():    text.insert(END, "7")def insert_8():    text.insert(END, "8")def insert_9():    text.insert(END, "9")def insert_plus():    text.insert(END, "+")def insert_minus():    text.insert(END, "-")def insert_divide():    text.insert(END, ":")def insert_multiply():    text.insert(END, "*")def insert_ac():    text.delete(0.0, END)def insert_equals():    text.delete(0.0, END)    text.insert(END, "Calculating...")
查看完整描述

1 回答

?
DIEA

TA貢獻1820條經驗 獲得超2個贊

您可以創建兩個單獨的框架并將一個放在另一個的頂部


我創建了 fc 和 fc2 并將 fc 放在 fc2 之上


from random import *

from math import *

from tkinter import *


def insert_1():

    text.insert(END, "1")

def insert_2():

    text.insert(END, "2")

def insert_3():

    text.insert(END, "3")

def insert_4():

    text.insert(END, "4")

def insert_5():

    text.insert(END, "5")

def insert_6():

    text.insert(END, "6")

def insert_7():

    text.insert(END, "7")

def insert_8():

    text.insert(END, "8")

def insert_9():

    text.insert(END, "9")

def insert_plus():

    text.insert(END, "+")

def insert_minus():

    text.insert(END, "-")

def insert_divide():

    text.insert(END, ":")

def insert_multiply():

    text.insert(END, "*")

def insert_ac():

    text.delete(0.0, END)

def insert_equals():

    text.delete(0.0, END)

    text.insert(END, "Calculating...")



calculator = Tk()

fc = Frame(calculator)

fc.grid(row=1)

fc2  = Frame(calculator)

fc2.grid(row = 2)

text = Text(fc, width=20, height=1)

bu1 = Button(fc2, text="1", activeforeground="white", activebackground="grey", command=insert_1)

bu2 = Button(fc2, text="2", activeforeground="white", activebackground="grey", command=insert_2)

bu3 = Button(fc2, text="3", activeforeground="white", activebackground="grey", command=insert_3)

bu4 = Button(fc2, text="4", activeforeground="white", activebackground="grey", command=insert_4)

bu5 = Button(fc2, text="5", activeforeground="white", activebackground="grey", command=insert_5)

bu6 = Button(fc2, text="6", activeforeground="white", activebackground="grey", command=insert_6)

bu7 = Button(fc2, text="7", activeforeground="white", activebackground="grey", command=insert_7)

bu8 = Button(fc2, text="8", activeforeground="white", activebackground="grey", command=insert_8)

bu9 = Button(fc2, text="9", activeforeground="white", activebackground="grey", command=insert_9)

bu_ac = Button(fc2, text="AC", activeforeground="white", activebackground="grey", command=insert_ac)

bu_plus = Button(fc2, text="+", activeforeground="white", activebackground="grey", command=insert_plus)

bu_minus = Button(fc2, text="-", activeforeground="white", activebackground="grey", command=insert_minus)

bu_divide = Button(fc2, text=":", activeforeground="white", activebackground="grey", command=insert_divide)

bu_multiply = Button(fc2, text="x", activeforeground="white", activebackground="grey", command=insert_multiply)

bu_equals = Button(fc2, text="=", activeforeground="white", activebackground="grey", command=insert_equals)






text.grid(row = 1)

bu1.grid(row=2, column=1)

bu2.grid(row=2, column=2)

bu3.grid(row=2, column=3)

bu4.grid(row=3, column=1)

bu5.grid(row=3, column=2)

bu6.grid(row=3, column=3)

bu7.grid(row=4, column=1)

bu8.grid(row=4, column=2)

bu9.grid(row=4, column=3)

bu_plus.grid(row=2, column=4)

bu_minus.grid(row=3, column=4)

bu_divide.grid(row=4, column=4)

bu_multiply.grid(row=2, column=5)

bu_ac.grid(row=3, column=5)

bu_equals.grid(row=4, column=5)



查看完整回答
反對 回復 2023-02-22
  • 1 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號