在我最近在python3.3写的代码,我想创建一个水果机是在早期阶段。看来,只要我使用“帮助”按钮,“ianh.gif”不显示。
from tkinter import *
def help(event):
global ian
Window=Tk()
Window.geometry('200x70')
Window.title('Need Help With Gambling addiction?')
canvas = Canvas(Window, width = 300, height = 300)
canvas.pack()
ian = PhotoImage(file = 'Images/Ianh.gif')
canvas.create_image(20,20, anchor=NW, image=img)
Window.mainloop()
def start_game(event):
Window=Tk()
Window.geometry('200x70')
Window.title('Fruit Machine')
Window=Tk()
Window.geometry('200x70')
Window.title('Main Menu')
canvas = Canvas(Window, width = 300, height = 300)
canvas.pack()
img = PhotoImage(file = 'Images/Cherries.gif')
canvas.create_image(20,20, anchor=NW, image=img)
L1=Label(Window, text="WELCOME TO THE FRUIT MACHINE")
L1.pack()
B1=Button(Window, text="Start")
B1.bind("<Button-1>",start_game)
B1.pack()
B2=Button(Window, text="Help")
B2.bind("<Button-1>",help)
B2.pack()
Window.mainloop()
里面的“帮助”的定义,照片图像和所有的帆布命令显示为他们应该不函数。
这应该工作:
def help(event):
global ian
Window=Toplevel()
Window.geometry('200x70')
Window.title('Need Help With Gambling addiction?')
canvas = Canvas(Window, width = 300, height = 300)
canvas.pack()
ian = PhotoImage(file = 'Images/Ianh.gif')
canvas.create_image(20,20, anchor=NW, image=ian)
多主循环()不工作。
如果你在寻找更多的结构来看看一个this。