我是一名正在研究编程问题的学生。我想知道我是否可以帮你做一个标签和标签
我目前正在为我的程序使用标签,因为它们看起来最好,而且与文本或其他类似的东西相比,更容易格式化。无论如何
我目前的问题是我的标签不会更新,我目前正在使用以下代码:
from tkinter import *
import sys
#Window Initilisation
root = Tk()
root.title('CafeAuLait Ordering')
#Product Prices
Cappu_CSt = (3.75) #Cappucino cost
#Defining Variables
TotaldCost = (0)
Reciptext = ('Developer Version')
Display = Label(root, width=35, bg='white', height=10, text=str(Reciptext))
Display.grid(row=1,column=3, columnspan=4, rowspan=8)
def button_cappucino():
global TotaldCost
global Reciptext
global Cappu_CSt
TotaldCost = TotaldCost + Cappu_CSt
Display = ((str(Reciptext) + '''
Cappucino ----- $'''+ str(Cappu_CSt)))
print('Test')
cappucino = Button(root, text='1x Cappucino',width=10 ,borderwidth=5, command=button_cappucino)
price_LabelCCP = Label(root, text='---$3.75', bg='#FFF6AD')
cappucino.grid(row=1, column=1)
price_LabelCCP.grid(row=1, column=2)
root.mainloop()
我在终端中得到了测试,这表明按钮确实在运行,但尽管如此,标签并没有更新,只保留文本“开发者版本”,有人知道我更新标签的简单方法吗?非常感谢
您正试图将文本直接分配给小部件。您必须将文本分配给适当的小部件属性。不过,你还有其他问题。我修正了你的逻辑,并在评论中解释了它
相关问题 更多 >
编程相关推荐