2
votes

How do I remove the title bar from a Toplevel() window in Tkinter. Right now I for my main I have

    self.master.title("Subtest")
    self.master.geometry("400x200")



    self.alertwindow()


    Label(self.master,textvariable=self.connected,height=4).grid(row=0,column=0)


    Button(self.master,text="Monitor",command= lambda: self.startnewthread(1),width=10).grid(row=6,column=1)
    Button(self.master,text="Quit",command=self.haltprogram).grid(row=6,column=0)

And for my alert window function I have

def alertwindow(self):
self.listbox=Listbox(Toplevel(self.master,width=150).overrideredirect(True),width=150).pack)

I was wanting the program to open up a root window, and then a toplevel listbox without a title bar; however, the only thing the program is doing right now is freezing, and when I remove the .overrideredirect(True), the program launches two listbox windows. How can I have the program open only one listbox without a title bar on windows? Thanks

1
do you need to actually call pack in the last line of code you posted? Listbox(Toplevel(...).pack()) As it is, you're passing a method where Tkinter expects a Widget. I'm not sure what that would actually do when you try to run the program, but it wouldn't be what you want it to do in any event...mgilson

1 Answers

2
votes

Looking at this line

self.listbox=Listbox(Toplevel(self.master,width=150).overrideredirect(True),width=150).pack)

It's pretty clear you're trying to do WAY too much on 1 line. (Your parenthesis don't even match). Let's break it up, shall we?

new_top = Toplevel(self.master,width=150)
new_top.overrideredirect(True)
self.listbox = Listbox(new_top,width=150)
self.listbox.pack()

Also note that you seem to be using .grid and .pack -- Generally that's ill advised and Tkinter will happily spend all of eternity trying to negotiate a proper placement of a widget when you try to use them together.


My guess about what's happening:

  • your actual code has properly balanced parenthesis so there is no SyntaxError
  • Toplevel.overrideredirct returns None
  • Listbox sees None as the parent widget and substitutes the root widget (Tk)
  • Then you're using .grid and .pack both on the root widget which causes your program to hang.