2

I am trying to write a program that allows the user to press different buttons in a full screen Tkinter GUI. The operations these buttons preform does not matter for my question, but I am having trouble creating a popup dialogue (askokcancel) to confirm that the user wants to press a button, then run the rest of that buttons code normally if "ok" is pressed. Currently, I have this program running from boot through the /etc/profile file, accessed via

sudo nano /etc/profile

Here I change the directory to the folder containing my python file and have it load my code, and upon booting up it loads my buttons correctly and upon pressing the correct button the popup window appears over the full screen window. However, when I try to run my code through the desktop shell, upon pressing the button, the popup window DOES appear, but is hidden behind the root window. I am not able to click anywhere else, and pressing "tab" and "enter" allows me to navigate between the two choices and pick one, but without being able to see it. I have buttons printing words in the shell, so I know the popup window is actually there.

The full screen makes use of the overrideredirect function, hiding the task bar and other options. When this is set to FALSE, the popup works as intended, but I am trying to make the GUI be the only thing on the screen.

Here is a condensed version of my code:

from Tkinter import*
import tkMessageBox

class Application(Frame):
    def run(self):
        tkMessageBox.askokcancel("Run Confirmation!", "Are you sure?")
        print "RUN Code Intitates"

    def createWidgets(self):
        self.button1 = Button(self,height=15,width=20)
        self.button1["command"] = self.run
        self.button1.pack({"side": "left"})

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.createWidgets()

root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (800, 480))

app = Application(master=root)
app.mainloop()
root.destroy()

I am by no means a computer science major and have only been working with raspberry pi, tkinter, and python for a couple weeks, so if I am missing something basic I apologize. I am using an 8" touchscreen display made for raspberry pi as my screen.

j_4321
  • 15,431
  • 3
  • 34
  • 61
MikeB
  • 21
  • 1

1 Answers1

-1

According to the tcl/tk documentation:

Setting the override-redirect flag for a window causes it to be ignored by the window manager; among other things, this means that the window will not be reparented from the root window into a decorative frame and the user will not be able to manipulate the window using the normal window manager mechanisms

So the window does not always behave has expected (it is less the case in Windows). For instance, in Linux, the window does not get keyboard focus (python tkinter overrideredirect; cannot receive keystrokes (Linux)).

  • If what you really care about is to have a fullscreen GUI, just replace

    root.overrideredirect(1)

    by

    root.attributes('-fullscreen', True)

    and the window will behave normally so the message box will appear on top of the main window.

  • Another possibility in Linux is to replace

    root.overrideredirect(1)

    by

    root.attributes('-type', 'dock')

    This tells the window manager to treat the window as a dock, and at least in XFCE, it results in a window with no decorations, always on top of the other windows, but the message box does appear on top of it.

j_4321
  • 15,431
  • 3
  • 34
  • 61