开发者社区> 问答> 正文

在Python中使用Tkinter时文本未更改

我正在为学校制作一个有关威尔士历史和传说的项目,但是当我单击它们时,无法使用两个按钮(英语和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

展开
收起
is大龙 2020-03-24 15:32:01 493 0
1 条回答
写回答
取消 提交回答
  • 您不需要在命令=函数末尾使用()

    例如: 代替

    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

    2020-03-24 15:32:10
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载