Creating a menuBar in a frame?

2024/7/6 21:28:47
import Tkinter as tk
from Tkinter import Label, StringVar, Entry, Button, Menu, Frame, Tk, Canvas
import subprocess
from Tkconstants import LEFT, CENTER,W, SUNKEN , X, Yclass SampleApp(tk.Tk):def __init__(self, *args, **kwargs):tk.Tk.__init__(self, *args, **kwargs)container = tk.Frame(self)container.pack(side="top", fill="both", expand=True)container.grid_rowconfigure(0, weight=1)container.grid_columnconfigure(0, weight=1)print "Hellooo Stack"self.frames = {}for F in (MainWindow,Master):frame = F(container, self)self.frames[F] = frameframe.grid(row=0, column=0, sticky="nsew")self.show_frame(MainWindow)def show_frame(self, c):'''Show a frame for the given class'''frame = self.frames[c]frame.tkraise()
class MainWindow(tk.Frame):def __init__(self, parent, controller):tk.Frame.__init__(self, parent)button = tk.Button(self, text="Connections",compound=LEFT)button.pack(pady=50)button1 = tk.Button(self, text="   Locker            ", compound=LEFT,command=lambda: controller.show_frame(Master))button1.pack(pady=50)class Master(tk.Frame): def __init__(self, parent, controller):tk.Frame.__init__(self, parent)menubar = Menu(self)filemenu = Menu(menubar,tearoff=0)filemenu.add_command(label="New",)filemenu.add_command(label="Open",)filemenu.add_command(label="Save As..")filemenu.add_command(label="Colour")filemenu.add_command(label="Close")menubar.add_cascade(label="File",menu=filemenu)controller.configure(menu = menubar)
if __name__ == "__main__":app = SampleApp()app.title("APPS")app.mainloop()

the above code which i posted works fine but the menu displays in all the windows but i wanted the menu to displayed in only one window....i used controller.configure so the menu is displayed in all windows but if i use self.configure i am getting an error...can some one please help me

Answer

You cannot attach a menu to a frame. The only widget with a menu option is the root window and Toplevel windows.

If you want to put a menu inside a frame, you will need to create a frame, add one or more Menubutton widgets, and attach a menu to each of those.

https://en.xdnf.cn/q/120233.html

Related Q&A

Python return dictionary [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Use selenium and python to move mouse outside of web page area

I need to test the exit intent form on this page: https://www.graphicproducts.com/guides/5s-system/When the mouse pointer is moved outside of the web page area a popup window appears. I then need to en…

Python „stack overflow” (104 if statements). Is def(x) the only solution to optimise code?

Today have tried to check files with path directory name. Previously it worked, until I tried to create 104 if/else statements. How to dispose of this overflow error? More specific question: Does def(…

How to fix Python restarting whenever I start program on IDLE environment?

import randomwinning_conditon = 0 no_of_guesses = 0 comp_guess = random.randint(1,100)while (no_of_guesses == 11) or (winning_conditon == 1):user_guess = int(input("What is your guess? "))if…

Fetching Lawyers details from a set of urls using bs4 in python

I am an absolute beginner to Web Scraping using Python and know very little about programming in Python. I am just trying to extract the information of the lawyers in the Tennessee location. In the web…

Having trouble with python simple code running in console [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

.upper not working in python

I currently have this codenum_lines = int(input()) lines = [] tempy = ctr = 1 abc = {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z } for i in range(0, num_lines):tempy = input()lines.append([])l…

Python SKlearn fit method not working

Im working on a project using Python(3.6) and Sklearn.I have done classifications but when I try to apply it for reshaping in order to use it with fit method of sklearn it returns an error. Heres what …

extracting n grams from huge text

For example we have following text:"Spark is a framework for writing fast, distributed programs. Sparksolves similar problems as Hadoop MapReduce does but with a fastin-memory approach and a clean…

Python: Input validate with string length

Ok so i need to ensure that a phone number length is correct. I came up with this but get a syntax error.phone = int(input("Please enter the customers Phone Number.")) if len(str(phone)) == 1…