user4772964
user4772964

Reputation:

Tkinter: menu not displayed

I run this code which aim is only to display a menu bar.

There is a simple menu bar in which 3 sub-menus are created without performing anything except for the Exit one which closes the window:

from Tkinter import *
import tkMessageBox
import numpy as np
import ttk
import tkFont
from PIL import ImageTk, Image
from tkColorChooser import askcolor
from tkFileDialog import askopenfilename
class MyGui(Frame):

   def __init__(self,master):
       Frame.__init__(self,master)
       self.master=master
       self.themenus() # menu initialization within the constructor

   def themenus(self):
       self.menubar=Menu(self.master)

       self.filemenu=Menu(self.menubar,tearoff=0)
       self.filemenu.add_command(label="Open Image")
       self.filemenu.add_command(label="Save Image")
       self.filemenu.add_command(label="Exit",command=self.master.quit)

       self.menubar.add_cascade(label="File",menu=self.filemenu)

if __name__=="__main__":
   root=Tk()
   root.wm_title("Test")
   mg=MyGui(root)
   root.mainloop()

I get this error:

libdc1394 error: Failed to initialize libdc1394

How to fix this ?

EDIT:

I resolved the problem by removing away the original imports that I did not use after all:

import tkMessageBox
import numpy as np
import ttk
import tkFont
from PIL import ImageTk, Image
from tkColorChooser import askcolor
from tkFileDialog import askopenfilename

Now, no error is triggered, however I do not see the menu displayed. Why ?

Upvotes: 0

Views: 528

Answers (1)

user4772964
user4772964

Reputation:

I resolved my problem by adding this line at the end of themenus() function:

self.master.config(menu=self.menubar)

Upvotes: 1

Related Questions