从tkinter导入* 根= Tk() answer = StringVar() disp = Entry(root,bg =“ blue”,font =(“ bold”,20),bd = 20,textvariable = answer.grid(row = 0,coloumnspan = 4) btn1 = Button(root,text =“ 1”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 1,coloumn = 0) btn2 = Button(root,text =“ 2”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 1,coloumn = 1) btn3 = Button(root,text =“ 3”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 1,coloumn = 2) btn4 = Button(root,text =“ 4”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 2,coloumn = 0) btn5 = Button(root,text =“ 5”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 2,coloumn = 1) btn6 = Button(root,text =“ 6”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 2,coloumn = 2) btn7 = Button(root,text =“ 7”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 3,coloumn = 0) btn8 = Button(root,text =“ 8”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 3,coloumn = 1) btn9 = Button(root,text =“ 9”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 3,coloumn = 2) btn0 = Button(root,text =“ 0”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 4,coloumn = 2) btn_add =按钮(root,text =“ +”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 1,coloumn = 3) btn_sub = Button(root,text =“-”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 2,coloumn = 3) btn_mul = Button(root,text =“ x”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 3,coloumn = 3) btn_div =按钮(root,text =“%”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 4,coloumn = 0) btn_equl =按钮(root,text =“ =”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 4,coloumn = 1) btn_clr =按钮(root,text =“ CLR”,padx = 10,bg =“ white”,fg =“ black”,font =(“ bold”,20))。grid(row = 4,coloumn = 3) root.mainloop()
答案 0 :(得分:0)
$ yarn --version
0.32
代替column
,coloumn
代替columnspan
答案 1 :(得分:0)
仅使用column
而不是coloumn
和coloumnspan
而不是columnspan
from tkinter import *
root = Tk()
answer = StringVar()
disp = Entry(root, bg="blue", font=("bold", 20), bd=20, textvariable=answer).grid(row=0, columnspan=4)
btn1 = Button(root, text="1", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=1, column=0)
btn2 = Button(root, text="2", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=1, column=1)
btn3 = Button(root, text="3", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=1, column=2)
btn4 = Button(root, text="4", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=2, column=0)
btn5 = Button(root, text="5", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=2, column=1)
btn6 = Button(root, text="6", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=2, column=2)
btn7 = Button(root, text="7", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=3, column=0)
btn8 = Button(root, text="8", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=3, column=1)
btn9 = Button(root, text="9", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=3, column=2)
btn0 = Button(root, text="0", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=4, column=2)
btn_add = Button(root, text="+", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=1, column=3)
btn_sub = Button(root, text="-", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=2, column=3)
btn_mul = Button(root, text="x", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=3, column=3)
btn_div = Button(root, text="%", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=4, column=0)
btn_equl = Button(root, text="=", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=4, column=1)
btn_clr = Button(root, text="CLR", padx=10, bg="white", fg="black", font=("bold", 20)).grid(row=4, column=3)
root.mainloop()
我总是喜欢这样分两步进行:
from tkinter import *
root = Tk()
answer = StringVar()
disp = Entry(root, bg="blue", font=("bold", 20), bd=20, textvariable=answer)
btn1 = Button(root, text="1", padx=10, bg="white", fg="black", font=("bold", 20))
btn2 = Button(root, text="2", padx=10, bg="white", fg="black", font=("bold", 20))
btn3 = Button(root, text="3", padx=10, bg="white", fg="black", font=("bold", 20))
btn4 = Button(root, text="4", padx=10, bg="white", fg="black", font=("bold", 20))
btn5 = Button(root, text="5", padx=10, bg="white", fg="black", font=("bold", 20))
btn6 = Button(root, text="6", padx=10, bg="white", fg="black", font=("bold", 20))
btn7 = Button(root, text="7", padx=10, bg="white", fg="black", font=("bold", 20))
btn8 = Button(root, text="8", padx=10, bg="white", fg="black", font=("bold", 20))
btn9 = Button(root, text="9", padx=10, bg="white", fg="black", font=("bold", 20))
btn0 = Button(root, text="0", padx=10, bg="white", fg="black", font=("bold", 20))
btn_add = Button(root, text="+", padx=10, bg="white", fg="black", font=("bold", 20))
btn_sub = Button(root, text="-", padx=10, bg="white", fg="black", font=("bold", 20))
btn_mul = Button(root, text="x", padx=10, bg="white", fg="black", font=("bold", 20))
btn_div = Button(root, text="%", padx=10, bg="white", fg="black", font=("bold", 20))
btn_equl = Button(root, text="=", padx=10, bg="white", fg="black", font=("bold", 20))
btn_clr = Button(root, text="CLR", padx=10, bg="white", fg="black", font=("bold", 20))
disp.grid(row=0, columnspan=4)
btn1.grid(row=1, column=0)
btn2.grid(row=1, column=1)
btn3.grid(row=1, column=2)
btn4.grid(row=2, column=0)
btn5.grid(row=2, column=1)
btn6.grid(row=2, column=2)
btn7.grid(row=3, column=0)
btn8.grid(row=3, column=1)
btn9.grid(row=3, column=2)
btn0.grid(row=4, column=2)
btn_add.grid(row=1, column=3)
btn_sub.grid(row=2, column=3)
btn_mul.grid(row=3, column=3)
btn_div.grid(row=4, column=0)
btn_equl.grid(row=4, column=1)
btn_clr.grid(row=4, column=3)
mainloop()