我是python的新手,我正在尝试tkinter。目前,我正在使用random
从列表中进行选择。当选择列表时,我希望某些按钮出现。等等,当选择了Pinoeer Mrt时,Button1出现供我单击,否则,如果选择了其他按钮,则出现相同的按钮但执行另一项功能。
我已向stackoverflow寻求帮助,但似乎找不到与我的需求相关的任何东西。如果您有任何链接,请在下面评论,我会看一下。谢谢!
def lunchLocation():
location_list = ['Pinoeer Mrt', 'Joo Koon Mrt', 'Avenue 3 - Hot Sun', 'Walk 1km - Hot Sun']
Location = random.choice(location_list)
print("Today we eat at ",Location ," lah!")
def foodChoicePinoeer():
ryan_Pinoeer = ['Minced Meat Noodle', 'Hotplate Chicken', 'fishball Soup']
elieen_Pinoeer = ['Hotplate Chicken', 'fishballNoodle' , 'banMian']
tommy_Pinoeer = ['Chicken Rice', 'Hotplate chicken', 'Chai Fan']
rob_Pinoeer = ['Hotplate Chicken', 'Ban Mian', 'Minced Meat Noodle']
ryan = random.choice(ryan_Pinoeer)
print("Today Ryan eat ",ryan_Pinoeer, 'ok?')
print("/nWhile Elieen eat ",elieen_Pinoeer,'lah !')
print("/nAnd Tommy will eat ",tommy_Pinoeer,'!!')
print("/nLastly rob will eat ",rob_Pinoeer," hor")
root = tk.Tk()
canvas1 = tk.Canvas(root, width=500, height=500)
canvas1.pack()
button1 = tk.Button(text='Choose Food', command=foodChoicePinoeer(), bg='brown', fg='white')
canvas1.create_window(300, 150, window=button1)
root.mainloop()
答案 0 :(得分:0)
您可以简单地将not_selected
方法移至create_window
函数中。添加一个lunchLocation
子句以检查位置是否符合您的要求。
if