Python 3.3 Tkinter Fullscreen - Taskbar not Hiding

Jason Swails jason.swails at gmail.com
Thu Apr 4 09:49:36 EDT 2013


I've added some comments about the code in question as well...

On Wed, Apr 3, 2013 at 11:45 PM, <teslafrequency at aol.com> wrote:

> Hi, I am working with Tkinter, and I have set up some simple code to run:
>
> import tkinter
> import re
> from tkinter import *
>

If you import everything from tkinter into your top-level namespace, then
the "import tkinter" at the top serves no purpose.


> global master
>

This 'global master' statement does nothing (and is actually misleading
IMO).


> master = Tk()
>
> # Start game Launcher
> def FormGUI():
>     master.title("GAME TITLE")
>     SW = master.winfo_screenwidth() / 3.2
>     SH = master.winfo_screenheight() / 3.2
>     master.geometry("500x300+%d+%d" % (SW, SH))
>     Label(master,text="game:\nGAME TITLE").pack()
>     Button(master, text="Start game", command=DestroyStart,
> takefocus=1).pack()
>     master.wm_state(zoom)
>

What is "zoom"?  This variable is not defined.  In fact, I get a NameError
when I try running your code because of this:

Traceback (most recent call last):
  File "test_tk.py", line 38, in <module>
    FormGUI()
  File "test_tk.py", line 18, in FormGUI
    master.wm_state(zoom)
NameError: global name 'zoom' is not defined

If I change zoom to "normal" (with quotes), it appears to work (although
I'm testing on Linux, not Windows).


> # Destroy the GUI launcher window upon player starting the game.
> def DestroyStart():
>     global master
>     master.destroy()
>     master = Tk()
>     ReformGui()
>
> # Form the game's GUI window in full screen.
> def ReformGui():
>     master.title("GAME TITLE")
>     SW = master.winfo_screenwidth()
>     SH = master.winfo_screenheight()
>     master.geometry("%dx%d+0+0" % (SW,SH))
>     master.attributes("-fullscreen", 1)
>     master.configure(bg="black")
>     Label(master, text="\"GAME TESTING TEXT\"",
>     background="black", foreground="white").pack()


> FormGUI()
>
> master.mainloop()
>
> # END OF CODE
>
> Everything in this code runs appropriately. The main goal of this code is
> to open up two windows, one with fixed dimensions, the other with
> full-screen enabled.
>
> My problem is that with the code above, the full-screen window opens up
> properly, however my taskbar shows over the full-screen. Until I click on
> the full-screen window, the taskbar will not be hidden.
>
> Am I doing something wrong, or is there a better way to create a
> full-screen window in Tkinter with the taskbar hidden?
>

This sounds to me that your full screen window does not have the focus
(i.e., it is not the `active' window).  Try adding a "master.focus_force()"
call in the ReformGui function to force it to take focus.  Note that
focus_force() is often considered 'impolite'---it's akin to that kid that
always needs to be the center of attention. Of course it's not as bad as
master.grab_set_global :)

If your application already has 'focus', then you can use focus_set instead
of focus_force.  The problem may be that you are destroying the original
master window and re-creating another (I typically avoid destroying the
root window mid-application).

Also as a note, it would be helpful to have some kind of button or
something to exit the app or exit fullscreen.  I had to Alt-F4 in order to
quit your sample program ;).

Hope this helps,
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130404/e09b69e6/attachment.html>


More information about the Python-list mailing list