Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python 3.3 Tkinter Fullscreen - Taskbar not Hiding

Reply
Thread Tools

Python 3.3 Tkinter Fullscreen - Taskbar not Hiding

 
 
teslafrequency@aol.com
Guest
Posts: n/a
 
      04-04-2013
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.
 
Reply With Quote
 
 
 
 
Jason Swails
Guest
Posts: n/a
 
      04-04-2013
I've added some comments about the code in question as well...

On Wed, Apr 3, 2013 at 11:45 PM, <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Rotwang
Guest
Posts: n/a
 
      04-04-2013
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, <(E-Mail Removed)
> <(E-Mail Removed)>> 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.
 
Reply With Quote
 
teslafrequency@aol.com
Guest
Posts: n/a
 
      04-04-2013
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!
 
Reply With Quote
 
Jason Swails
Guest
Posts: n/a
 
      04-04-2013
On Thu, Apr 4, 2013 at 1:30 PM, Rotwang <(E-Mail Removed)> 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, <(E-Mail Removed)
>> <(E-Mail Removed)**>> 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

 
Reply With Quote
 
Rotwang
Guest
Posts: n/a
 
      04-04-2013
On 04/04/2013 20:00, Jason Swails wrote:
> On Thu, Apr 4, 2013 at 1:30 PM, Rotwang <(E-Mail Removed)
> <(E-Mail Removed)>> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tkinter fullscreen with Mac OS X C Martin Python 3 08-07-2008 09:20 PM
Delphi 2007 + Themed support + WinXP64Pro + Side Taskbar = System Crash + Taskbar not working. Skybuck Flying Windows 64bit 4 08-27-2007 02:17 PM
Script for Hiding/Un-Hiding Text On Click Ste Javascript 41 08-01-2007 02:35 PM
Day shown on taskbar and unable to make settings on taskbar displays. Charlie Evans Computer Support 4 05-31-2005 03:01 PM
Hiding taskbar in OE Robin Computer Support 0 08-08-2004 01:32 PM



Advertisments