Reputation: 1383
I'm looking for a way to create a full screen window and not showing console (or the borders), and escape the full screen when 'escape' is pressed. I have tried to rename the extension from 'py' to 'pyw', but it didn't hide the side bar as some suggested.
Here is my code to maximize the window, but it doesn't hide the console:
def __init__(master): #I'm using tkinter for my GUI
master = master
width, height = master.winfo_screenwidth(), master.winfo_screenheight()
master.geometry("%dx%d+0+0" % (width, height))
In addition, I need to use the script on both Mac and Windows, are they working differently if I need to hide the console?
I have tried overrideredirect(True)
, but it doesn't allow me to use keyboard, which is required for my task. I also tried wm_attributes('-fullscreen', True)
, but it doesn't create exactly full screen, there's empty place at the top where the Mac Taskbar existed.
So is there any way that allows me use full screen without the toolbar (MacOS), and the keyboard works?
Thanks!
Upvotes: 1
Views: 4359
Reputation: 321
How about this for the screen resolution:
from Tkinter import *
import ttk
def escape(root):
root.geometry("200x200")
def fullscreen(root):
width, height = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (width, height))
master = Tk()
width, height = master.winfo_screenwidth(), master.winfo_screenheight()
master.geometry("%dx%d+0+0" % (width, height))
master.bind("<Escape>", lambda a :escape(master))
#Added this for fun, when you'll press F1 it will return to a full screen.
master.bind("<F1>", lambda b: fullscreen(master))
master.mainloop()
And this for no border (taken from here):
import tkinter as tk
root = tk.Tk()
root.attributes('-alpha', 0.0) #For icon
#root.lower()
root.iconify()
window = tk.Toplevel(root)
window.geometry("100x100") #Whatever size
window.overrideredirect(1) #Remove border
#window.attributes('-topmost', 1)
#Whatever buttons, etc
close = tk.Button(window, text = "Close Window", command = lambda: root.destroy())
close.pack(fill = tk.BOTH, expand = 1)
window.mainloop()
The only solution for the console is to save the file as .pyw as you've already read. You can also try to override the Tk functions using overrideredirect(1)
but that would be more complicated.
Hopefully this will help you, Yahli.
Upvotes: 1