here is a snippet of code from my first attempt at a GUI.
When the 'Submit' button is pushed, I would like to display a label and OptionMenu below the button. I have got the label working, and searched around for a solution, but I just cannot get the OptionMenu working. Any help would be much appreciated!
The error I receive is:
self._root = master._root()
AttributeError: 'MyApp' object has no attribute '_root'
My code:
from tkinter import *
class MyApp:
def __init__(self, master):
self.master = master
master.title("My Application")
master.minsize(width=800, height=800)
master.maxsize(width=800, height=800)
##### Setup & Display the Labels
self.headerLabel = Label(master, text="Label")
self.headerLabel.grid(row=0, sticky=E)
self.headerEntry = Label(master, text="Enter")
self.headerEntry.grid(row=0, column=1, sticky=N)
##### Submit Button
self.getButton = Button(root, text="Submit", command=self.dostuff_button)
self.getButton.grid(row=7, column=1)
def dostuff_button(self):
self.inputfumelevel()
def inputfumelevel(self):
self.inpfumeLabel = Label(text="Input Your Fume Level")
self.inpfumeLabel.grid(row=12, column=0)
self.fumeEntry = StringVar(self)
self.fumeEntry.set("Select Fume")
self.fumeEntryOM = OptionMenu(self, self.fumeEntryOM, '1', '2', '3')
self.fumeEntryOM.grid(row=12, column=1)
root = Tk()
my_gui = MyApp(root)
root.mainloop()