我正在为学校制作一个有关威尔士历史和传说的项目,但是当我单击它们时,无法使用两个按钮(英语和C兰)来更改两个标签。任何帮助将不胜感激!!
from tkinter import BOTH, Canvas
from tkinter import \*
Titlet = 'Welsh History And Legends'
startt = 'Click Here To Start'
master = tk.Tk()
master.title('2020 Coding Challenge - Josh Allan')
master.configure(background = 'black')
def English():
Titlet = 'Welsh History And Legends'
startt = 'Click Here To Start'
def Welsh():
Titlet = 'Hanes A Chwedlau Cymraeg'
startt = 'Cliciwch Yma I Cychwyn'
title = tk.Label(master, text = (Titlet), font = 'fixedsys 20 bold', fg = 'white', background = 'black')
title.grid(row = 0, columnspan = 2)
ph = tk.Label(master, bg = 'black')
ph.grid(row=2)
LangE = tk.Button(master, text = 'English', font = 'Verdana 9 bold', fg = 'gray', background = 'black', command = English())
LangE.grid(row = 3, column = 0)
LangC = tk.Button(master, text = 'Cymraeg', font = 'Verdana 9 bold', fg = 'gray', background = 'black', command = Welsh())
LangC.grid(row = 3, column = 1)
ph = tk.Label(master, bg = 'black')
ph.grid(row=4)
press_start = tk.Button(master, text = (startt), font = 'Verdana 9 bold', fg = 'gray', background = 'black')
press_start.grid(row = 5, columnspan = 2)
tk.mainloop()
问题来源:stackoverflow
您不需要在命令=函数末尾使用()
例如: 代替
LangE = tk.Button(master, text = 'English', font = 'Verdana 9 bold', fg = 'gray', background = 'black', command = English())
放
LangE = tk.Button(master, text = 'English', font = 'Verdana 9 bold', fg = 'gray', background = 'black', command = English)
回答来源:stackoverflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。