Python 3.3 Tkinter Fullscreen - Taskbar not Hiding

Discussion in 'Python' started by teslafrequency@aol.com, Apr 4, 2013.

  1. Guest

    Hi, I am working with Tkinter, and I have set up some simple code to run:

    import tkinter
    import re
    from tkinter import *

    global master
    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)

    # 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?

    Note: Removing the 'import re' code above fixes the taskbar problem, however the re module is apparently needed as I can't run the program properly as an executable. Importing re fixes this problem. I'm running this program under Windows.
     
    , Apr 4, 2013
    #1
    1. Advertising

  2. Jason Swails Guest

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

    On Wed, Apr 3, 2013 at 11:45 PM, <> 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
     
    Jason Swails, Apr 4, 2013
    #2
    1. Advertising

  3. Rotwang Guest

    On 04/04/2013 14:49, Jason Swails wrote:
    > I've added some comments about the code in question as well...
    >
    > On Wed, Apr 3, 2013 at 11:45 PM, <
    > <mailto:>> 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.


    I don't know whether this applies to the OP's code, but I can think of
    at least one reason why one would want both "import module" and "from
    module import*" at the top of one's code: monkey patching.
     
    Rotwang, Apr 4, 2013
    #3
  4. Guest

    Thanks a lot for your help, I've implemented the code you suggested and it seems to be functioning properly now. I've cleaned up the code a bit as well. I'll also take into account not destroying the master. Thanks again for your help!
     
    , Apr 4, 2013
    #4
  5. Jason Swails Guest

    On Thu, Apr 4, 2013 at 1:30 PM, Rotwang <> wrote:

    > On 04/04/2013 14:49, Jason Swails wrote:
    >
    >> I've added some comments about the code in question as well...
    >>
    >> On Wed, Apr 3, 2013 at 11:45 PM, <
    >> <mailto:**>> 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.
    >>

    >
    > I don't know whether this applies to the OP's code, but I can think of at
    > least one reason why one would want both "import module" and "from module
    > import*" at the top of one's code: monkey patching.



    That was not happening in the OP's code (it actually had no references to
    tkinter after the initial import). That said, if you change any attributes
    inside tkinter (by binding names inside tkinter to another object) after
    the top three lines, those changes will not percolate down to the
    attributes imported via "from tkinter import *" -- you would obviously have
    to do that work before importing the tkinter namespace into the toplevel
    namespace.

    I'd be interested to see if there's actually an example where someone does
    this in a way that would not be done better another way. In any case, it
    served no purpose in this particular program :).


    All the best,
    Jason
     
    Jason Swails, Apr 4, 2013
    #5
  6. Rotwang Guest

    On 04/04/2013 20:00, Jason Swails wrote:
    > On Thu, Apr 4, 2013 at 1:30 PM, Rotwang <
    > <mailto:>> wrote:
    > [...]
    >
    > I don't know whether this applies to the OP's code, but I can think
    > of at least one reason why one would want both "import module" and
    > "from module import*" at the top of one's code: monkey patching.
    >
    >
    > That was not happening in the OP's code (it actually had no references
    > to tkinter after the initial import).


    Sure.


    > That said, if you change any
    > attributes inside tkinter (by binding names inside tkinter to another
    > object) after the top three lines, those changes will not percolate down
    > to the attributes imported via "from tkinter import *" -- you would
    > obviously have to do that work before importing the tkinter namespace
    > into the toplevel namespace.


    What I had in mind was something like this:

    # begin module derp.py

    global_variable = 4

    def f():
    print('global_variable == %i' % global_variable)

    # end module derp.py

    >>> # in the interactive interpreter...
    >>> import derp
    >>> from derp import *
    >>> global_variable = 5
    >>> f()

    global_variable == 4
    >>> derp.global_variable = 5
    >>> f()

    global_variable == 5


    Off the top of my head I don't know whether there's any purpose to doing
    that kind of thing with tkinter, but I can conceive that it might be
    useful for e.g. changing widget default behaviour or something.


    > I'd be interested to see if there's actually an example where someone
    > does this in a way that would not be done better another way.


    No idea, sorry.
     
    Rotwang, Apr 4, 2013
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Passero
    Replies:
    5
    Views:
    11,410
  2. =?Utf-8?B?S2VuIENoYXJsZXN3b3J0aA==?=

    Miminised Files do not show on the Taskbar

    =?Utf-8?B?S2VuIENoYXJsZXN3b3J0aA==?=, Feb 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    470
    =?Utf-8?B?S2VuIENoYXJsZXN3b3J0aA==?=
    Feb 21, 2007
  3. C Martin

    Tkinter fullscreen with Mac OS X

    C Martin, Jul 29, 2008, in forum: Python
    Replies:
    3
    Views:
    848
    Kevin Walzer
    Aug 7, 2008
  4. meagain
    Replies:
    1
    Views:
    321
    Evertjan.
    Mar 11, 2007
  5. Ste
    Replies:
    41
    Views:
    859
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
Loading...

Share This Page