tkinter - Drop down menu's python -
hello have started program display school time table code far:
from tkinter import * master = tk() master2 = tk() var = stringvar(master) var2 = stringvar(master2) var.set("day") var2.set("week") option = optionmenu(master, var, "monday", "tuesday", "wednesday", "thursday", "friday") option2 = optionmenu(master2, var, "a", "b") option.pack() option2.pack() week = var2.get() day = var.get() def ok(): if day == "monday" , week == "a": print("you have: \n p.s.e mrs smith \n w.b.q mrs smith \n science mr martin \n media wirh mr kelleher \n english mrs jenkins (of mice , men)") input("press enter close") if day == "tuesday" , week == "a": print("you have: \n r.m mr arnold/mr heywood \n english mrs jenkins \n i.c.t mr davies \n maths mr tucker \n i.t programing mr arnold ") input("press enter close") if day == "wednesday" , week == "a": print("you have: \n english mrs jenkins \n science mr martin \n re mr davies \n media mr kelleher \n r.m mr arnold/mr heywood ") input("press enter close") if day == "thursday" , week == "a": print("you have: \n games mr davies \n i.c.t mr davies \n i.t programing mr arnold \n science mr martin \n maths mr tucker") input("press enter close") if day == "friday" , week == "a": print("you have: \n maths mr tucker \n english mrs jenkins \n media mr kelleher \n i.t programing mr arnold \n science dr burton") input("press enter close") if day == "monday" , week == "b": print("you have: \n science dr burton \n re mr davies \n welsh mr kedward \n english mrs jenkins (of mice , men) \n media mr kelleher") input("press enter close") if day == "tuesday" , week == "b": print("you have: \n maths mr tucker \n r.m mr arnold/mr heywood \n i.t programing mr arnold \n i.c.t mr davies \n science dr burton") input("press enter close") if day == "wednesday" , week == "b": print("you have: \n r.m mr arnold/mr heywood \n media mr kelleher \n english mrs jenkins \n science miss fair \n i.c.t mr davies") input("press enter close") if day == "thursday" , week == "b": print("you have: \n games mr davies \n i.c.t mr davies \n i.t programing mr arnold \n maths mr tucker \n science miss fair") input("press enter close") if day == "friday" , week == "b": print("you have: \n welsh mr kedward \n science miss fair \n english mrs jenkins \n maths mr tucker r.m mr arnold/mr heywood") input("press enter close") else: print("error invalid choice") input("press enter close") button = button(master, text="ok", command=ok) button2 = button(master2, text="ok", command=ok) button.pack() button2.pack() mainloop()
i wondering how can display 2 options in same tkinter window not set value correct ones e.g: day not = monday , week not = instead = "day week" , wondering how fix thanks. new tkinter
there's 3 things here address. i'll them in order found them
multiple instances of tk
master = tk() master2 = tk() # don't
never have 2 instances of tk
running @ once. if need second window, use tkinter.toplevel
. don't need second window this, however, let's move on.
change inherited master
that includes var2
, option2
, , button2
. in fact since we're dropping master2
completely, delete button2
.
make stringvar
update when button pressed
this why function isn't receiving right info. assign day
, week
var.get()
, var2.get()
once, , right after create optionmenu
s when they're still on default values. when change optionmenu
item, day
, week
never change. instead like:
def ok(): global var, var2 day = var.get() week = var2.get() if day == ... ...
afterword
by way, mainloop
call should master.mainloop()
. run mainloop
instance of tk
, part of reason why shouldn't have more 1 instance! there's deal of inconsistency in variable naming schemes, i'll refer pep8 since it's bit outside of scope of answer. know things var
variable name vague , terrible, , day
, week
should classes if they're capitalized that. i'd recommend removing "press enter continue" lines. don't need them. in fact remove console interaction user: make toplevel
, write label
on it.
all in though, work! 1 of correct beginning forays tkinter i've seen in long time.
Comments
Post a Comment