0

In the code that i recently wrote in python3.3, I am trying to create a fruit machine and am in the early stages. It appears that as soon as i use the "help" button, "ianh.gif" doesn't display.

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()

Inside the 'help' defintion, PhotoImage and all canvas commands appear to not function as they're supposed to.

1 Answers1

0

This should work:

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)

Multiple mainloop() don't work well.

If you looking for more structure take a look a this.

Aoki Ahishatsu
  • 495
  • 1
  • 6
  • 15