How to remove dashed line from my UI menu?

I am trying to add the "Open File" tab in my user interface. It works fine, but the line --------- displayed at the top of the tab, and I want to delete it. I do not know why this line appears, and I cannot find the line in the code.

enter image description here

This is my code:

 # -*- coding: utf-8 -*- from Tkinter import * import Image import ImageTk import tkFileDialog class Planificador(Frame): def __init__(self,master): Frame.__init__(self, master) self.master = master self.initUI() def initUI(self): self.master.title("test") menubar = Menu(self.master, tearoff=0) self.master.config(menu=menubar) fileMenu = Menu(menubar) fileMenu.add_command(label="Open config file", command=self.onOpen) menubar.add_cascade(label="File", menu=fileMenu) fileMenu.add_separator() fileMenu.add_command(label="Exit", command=root.quit) self.txt = Text(self) self.txt.pack(fill=BOTH, expand=1) def onOpen(self): ftypes = [('Python files', '*.py'), ('All files', '*')] dlg = tkFileDialog.Open(self, filetypes = ftypes) fl = dlg.show() if fl != '': text = self.readFile(fl) self.txt.insert(END, text) def readFile(self, filename): f = open(filename, "r") text = f.read() return text # Main if __name__ == "__main__": # create interfacE root = Tk() aplicacion = Planificador(root) root.mainloop() 

I would like to know where I can remove this ------- from the code.
thanks in advance

+6
source share
2 answers

Set tearoff option fileMenu to False (or 0 )

 fileMenu = Menu(menubar, tearoff=False) 
+10
source

The best way to remove the dashed line is to use the option_add method to set the *tearOff from root to False before you start creating any menus. Here you can do it in your initUI method as follows:

 def initUI(self): self.master.title("test") self.master.option_add('*tearOff', False) 

This will remove the dashed line for each menu that you create, so you will not need to set tearoff=False at any time when creating the menu.

+3
source

Source: https://habr.com/ru/post/950508/


All Articles