-2

So im trying to make a problem for school which helps students access things easier, a part of this is getting all the PDF files they may need. Ive created a menu in Tkinter but the code will start without me choosing what to do.

import tkinter as tk
import webbrowser

root = tk.Tk()
root.title("School Tool")
root.geometry("300x300")
root.configure(background='black')


menu = tk.Menu(root, bg="blue")
root.config(menu=menu)


root = tk.Tk()
root.title("School Tool")
root.geometry("300x300")
root.configure(background='black')


menu = tk.Menu(root, bg="blue")
root.config(menu=menu)

def openKillersTears():
    url = 'http://www.python.org/'
    webbrowser.open_new(url)

class subMenu:
submenu = tk.Menu(menu, bg="Black", fg="white",tearoff=0)
menu7= tk.Menu(submenu, bg="Black", fg="white",tearoff=0)
menu8 = tk.Menu(submenu, bg="Black", fg="white",tearoff=0)
menu9 = tk.Menu(submenu, bg="Black", fg="white",tearoff=0)
menu10 = tk.Menu(submenu, bg="Black", fg="white",tearoff=0)
menu11 = tk.Menu(submenu, bg="Black", fg="white",tearoff=0)
menu12 = tk.Menu(submenu, bg="Black", fg="white",tearoff=0)

menuKillersTears = tk.Menu(menu9, bg="Black", fg="white",tearoff=0,)
menuKillersTears.add_command(label="Killers Tears", command=openKillersTears())

menu.add_cascade(label="PDF's", menu=submenu, )
submenu.add_cascade(label="Year 7", menu=menu7)
submenu.add_cascade(label="Year 8", menu=menu8)
submenu.add_cascade(label="Year 9", menu=menu9)
submenu.add_cascade(label="Year 10", menu=menu10)
submenu.add_cascade(label="Year 11", menu=menu11)
submenu.add_cascade(label="Year 12", menu=menu12)

menu7.add_cascade(label="English")
menu7.add_cascade(label="Math")
menu7.add_cascade(label="Science")
menu7.add_cascade(label="History / Humanities")

menu8.add_cascade(label="English")
menu8.add_cascade(label="Math")
menu8.add_cascade(label="Science")
menu8.add_cascade(label="History")

menu9.add_cascade(label="English", menu=menuKillersTears,)
menu9.add_cascade(label="Math")
menu9.add_cascade(label="Science")
menu9.add_cascade(label="History")

menu10.add_cascade(label="English")
menu10.add_cascade(label="Math")
menu10.add_cascade(label="Science")
menu10.add_cascade(label="History")

menu11.add_cascade(label="English")
menu11.add_cascade(label="Math")
menu11.add_cascade(label="Science")
menu11.add_cascade(label="History")

menu12.add_cascade(label="English")
menu12.add_cascade(label="Math")
menu12.add_cascade(label="Science")
menu12.add_cascade(label="History")

root.mainloop()

ill run it and it will connect to the site without me choosing the option on the menu, and when i do choose the option on the menu nothing happens

any ideas?

kajetons
  • 4,481
  • 4
  • 26
  • 37
Flikaa
  • 1
  • 1

1 Answers1

0

I haven't read it all but you need to remove the parenthesis when you bind the action:

menuKillersTears.add_command(label="Killers Tears", command=openKillersTears)

Otherwise the function will be called when the connection is made only.

Gwendal Grelier
  • 526
  • 1
  • 7
  • 21