Reputation: 112
I'm trying to build a menu for my application and in the menu bar, I have options for 'About me' and 'help page' under the help tab and the main menu in the File tab.
I'm creating Frames for the 'About me' and the 'help page' which should display relevant text upon clicking, and the main menu takes us to the 'main page'.
The issue I'm facing is that when I'm placing 'label text' in the 'help page', the main application screen displays that text, and the frame doesn't appear if choosing the 'help page' frame as a container. If I choose app(TK instance) as a container, permanent text displays even upon forgetting frames.
Here's the snippet:-
# Create window object
app = Tk()
##getting screen width and height of display
wide= app.winfo_screenwidth()
long= app.winfo_screenheight()
#setting tkinter window size
app.geometry("%dx%d" % (wide, long))
def aboutme():
hide_frames()
aboutme_frame.grid(row=0,column=0)
def helppage():
hide_frames()
var = StringVar()
label = Label(app, textvariable=var, relief=RAISED,bg='blue')
var.set("Hey!? How are you doing?")
label.grid(row=0,column=0)
help_page.grid(row=0,column=0)
def mainmenu():
hide_frames()
def hide_frames():
aboutme_frame.grid_forget()
help_page.grid_forget()
##Menu bar
menubar = Menu(app)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Main Menu",command=mainmenu)
filemenu.add_command(label="Exit", command=app.quit)
menubar.add_cascade(label="File", menu=filemenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help Index",command=helppage)
helpmenu.add_command(label="About...",command= aboutme)
menubar.add_cascade(label="Help", menu=helpmenu)
app.config(menu=menubar)
## Create frames
aboutme_frame = Frame(app,width=wide,height=long,bg='grey')
help_page = Frame(app,width=wide,height=long,bg='black')
# Start program
app.mainloop()
EDIT-- Added full program (part where Tkinter is being used)
Any suggestions?
Upvotes: 0
Views: 735
Reputation: 112
Thanks @toyota Supra for suggestion.
I was doing two mistakes basically, first invoking another grid for label and second placing label on grid without initializing frame grid hence I was seeing Label on main screen itself. Here's changes I made that worked..!
def helppage():
hide_frames()
var = StringVar()
help_page.grid(row=0,column=0)
help_label = Label(help_page, textvariable=var, relief=RAISED,bg='blue')
var.set("Hey!? How are you doing?")
help_label.place(relx = 0.5,
rely = 0.5,
anchor = 'center')
Upvotes: 1