Python Forum
[Tkinter] [python]Problem in creating menu[/python]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] [python]Problem in creating menu[/python]
#1
 I've saved the menu details in a dictionary, then I was trying to call it to create menu by using loop but its not working, can any body here help to find the solution and here is my code
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from tkinter import filedialog
import numpy as np


file_menu_dict = {'Open' : 'self.open_file()' ,
                         'Save' : '',
                         'Save as': '',
                         'Print' : '',
                         'Close' : '',
                         'Exit'  : '',                            
                        }

class My_actions():
    def __init__(self):#, **kwds): 
        pass
    def open_file(self ):
        file_name = filedialog.askopenfilename(filetypes=(("PNG","*.png"),("Gif","*.gif"),("All files","*.*")))
        image_file = open(file_name).read()
        print(image_file)

    def all_menu(self, main_menu , all_menu_dict):
        #File menu
        for i,j in all_menu_dict.items():    
            main_menu.add_command( label = i,  command = lambda : j)

class My_frame(My_actions):#My_actions):
    def __init__(self, **kwds):
        super().__init__()

        #Menu frame start
        self.menu_frame = LabelFrame(kwds['root'] )
        self.menu_frame.background = 'red'
        self.menu_frame.grid(row = 2, column = 0, columnspan=4, sticky= kwds['sticky'])#side  = menu_side)
                
        #Menu frame end
        
    def all_menu_frame(self, root):  
            #menu start here
            menubar = Menu(self.menu_frame)
            root.config(menu = menubar)
            file = Menu(menubar)
            
            menubar.add_cascade(menu=file, label="File")
            
            # Method to call file menu
            self.all_menu(file, file_menu_dict)

            #menu end here
#Class my frame for both menu & status menu  end here

def main():
    root = Tk()
    window_size_x=0
    window_size_y=0
        
    root.geometry("%dx%d+%d+%d" %(root.winfo_screenwidth(), root.winfo_screenheight(), window_size_x, window_size_y))
    
    actions = My_frame( root=root, frame_width=400, frame_height =50, sticky='S')    
    actions.all_menu_frame(root = root)
    

    root.mainloop()
 
if __name__ == '__main__' : main()
Reply


Messages In This Thread
[python]Problem in creating menu[/python] - by yamoon - Aug-01-2018, 05:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with python raarkil 22 7,279 Apr-30-2021, 01:05 PM
Last Post: raarkil
  I need help on creating a Python Software Chrype 5 4,521 Mar-04-2020, 03:50 PM
Last Post: Chrype
  [Tkinter] Problem with tkinter when creating .exe file Jan_97 2 4,730 Feb-27-2020, 05:17 PM
Last Post: Jan_97
  [Tkinter] macOS Catalina and Python menu issue SouthernYankee 7 7,037 Dec-11-2019, 02:02 AM
Last Post: chrstphrchvz
  Nesting menu buttons tkinter for python Mocap 1 2,803 Jul-18-2019, 11:46 AM
Last Post: metulburr
  Creating An Alert Tone through a python gui on chromium. Fluffyyyzzz 1 1,968 Aug-02-2018, 07:29 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020