繁体   English   中英

Button function 中的文本没有出现在我的 phyton Tkinter 中。 我正在使用 MacBook。 有人知道如何修复我的代码吗?

[英]the text in the Button function doesn't appear in my phyton Tkinter. I'm using a MacBooks. anyone has any idea how to fix my code?

有人可以帮我吗。 我似乎无法弄清楚为什么按钮的文本没有出现在我的界面 window 上。 我使用的是 Mac 操作系统。 '''

from Tkinter import *

root = Tk()

root.title("Simple Calculator")

e = Entry(root, width=35, borderwidth= 5)
e.grid(row=0, column=0, columnspan=3, padx=10, pady=10)

def button_add():
    return


button_1 = Button(root, text= "1",fg="red", padx = 40, pady =20, command=button_add)


button_2 = Button(root, text= "2", fg="red",padx = 40, pady =20, command=button_add)


button_3 = Button(root, text= "3", fg="red",padx = 40, pady =20, command=button_add)


button_4 = Button(root, text= "4", fg="red",padx = 40, pady =20, command=button_add)


button_5 = Button(root, text= "5",fg="red", padx = 40, pady =20, command=button_add)


button_6 = Button(root, text= "6", fg="red",padx = 40, pady =20, command=button_add)


button_7 = Button(root, text= "7", fg="red",padx = 40, pady =20, command=button_add)


button_8 = Button(root, text= "8", fg="red",padx = 40, pady =20, command=button_add)


button_9 = Button(root, text= "9",fg="red", padx = 40, pady =20, command=button_add)

# put buttons on the screen

button_1.grid(row= 3, column=0)

button_2.grid(row= 3, column=1)
button_3.grid(row= 3, column=2)

button_4.grid(row=2 , column=0)
button_5.grid(row= 2, column=1)
button_6.grid(row= 2, column=2)

button_7.grid(row= 1, column=0)
button_8.grid(row= 1, column=1)
button_9.grid(row= 1, column=2)



root.mainloop()

'''

请帮忙。 不知道为什么按钮的文字没有出现在界面window上。 它只显示为白色。

您的程序中有许多语法错误。 例如,通过 tkinter 的文档,Button 的正确语法是button_1 = tkinter.Button(root, text='1') kindy go。

注意:您的程序有许多不必要空格的缩进警告。 请努力。

试试下面的代码。

try:
    import tkinter
except ImportError:     # for python 2 user
    import Tkinter as tkinter


root = tkinter.Tk()
root.title("Simple Calculator")
e = tkinter.Entry(root, width=35, borderwidth= 5)
e.grid(row=0, column=0, columnspan=3, padx=10, pady=10)


def button_add():
    return


button_1 = tkinter.Button(root, text="1",fg="red", padx=40, pady=20, command=button_add)
button_2 = tkinter.Button(root, text="2", fg="red", padx=40, pady=20, command=button_add)
button_3 = tkinter.Button(root, text="3", fg="red", padx=40, pady=20, command=button_add)
button_4 = tkinter.Button(root, text="4", fg="red", padx =40, pady=20, command=button_add)
button_5 = tkinter.Button(root, text="5", fg="red", padx=40, pady=20, command=button_add)
button_6 = tkinter.Button(root, text="6", fg="red", padx=40, pady=20, command=button_add)
button_7 = tkinter.Button(root, text="7", fg="red", padx=40, pady=20, command=button_add)
button_8 = tkinter.Button(root, text="8", fg="red", padx=40, pady=20, command=button_add)
button_9 = tkinter.Button(root, text="9", fg="red", padx=40, pady=20, command=button_add)

# put buttons on the screen

button_1.grid(row=3, column=0)
button_2.grid(row=3, column=1)
button_3.grid(row=3, column=2)

button_4.grid(row=2 , column=0)
button_5.grid(row=2, column=1)
button_6.grid(row=2, column=2)

button_7.grid(row=1, column=0)
button_8.grid(row=1, column=1)
button_9.grid(row=1, column=2)

root.mainloop()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM