第一个问题是,当我单击“+ $16”按钮时,它没有显示增加,尽管您可以在关闭窗口并在 Python Shell 中输入钱后看到它。第二个问题是,在我添加了那些sticky=SE和sticky=SW窗口后,根本不会出现(没有错误消息)。
# money adder
import sys
from tkinter import *
import random
root = Tk()
root.geometry('360x160+800+200')
root.title('app')
money = 100
def addMoney():
global money
money = money + 16
def end():
global root
root.destroy()
appTitle = Label(root,text='Money Adder',font='Verdana 31',fg='lightblue').pack()
budget = Label(root,text='Budget: $'+str(money),font='Arial 21',fg='green').pack()
moneyButton = Button(root,text='+ $16',width=17,height=2,command=addMoney).grid(sticky=SW)
endButton = Button(root,text='Quit',width=5,height=2,command=end).grid(sticky=SE)
root.mainloop()