Tkinter main window focus

后端 未结 6 652
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 10:36

I have the following code

window = Tk()
window.lift()
window.attributes(\"-topmost\", True)

This co

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 11:08

    For Linux (Ubuntu 16.04.6 LTS) I tried many suggestions including .grab which broke things. In the end I used:

    if self.top2_is_active is True: # Are we already playing songs?
        self.top2.focus_force()     # Get focus
        self.top2.lift()            # Raise in stacking order
        root.update()
        return                      # Don't want to start playing again
    
    

    It's not really "stealing" focus because I have a button on the main window defined as:

    ''' ▶  Play Button '''
    self.play_text="▶  Play"                # play songs window is opened.
    self.listbox_btn2 = tk.Button(frame3, text=self.play_text, \
                        width=BTN_WID, command=self.play_items)
    self.listbox_btn2.grid(row=0, column=1, padx=2)
    

    After clicking this button the text is changed to:

    self.listbox_btn2 ["text"] = "

提交回复
热议问题