Created
January 11, 2016 20:43
-
-
Save emdete/5dabcbc099d881f889ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from tkinter import * | |
''' | |
Fullscreen test program using tkinter. Enter 'f' or F11 to make the current | |
window fullscreen. Enter 'o' to open a second window in fullscreen. | |
''' | |
class MainWindow(object): | |
def __init__(self): | |
self.state = False | |
self.toplevel = Tk() | |
self.toplevel.title('MainWindow') | |
self.toplevel.bind('<Control-q>', lambda e: self.toplevel.quit()) | |
self.toplevel.bind('q', lambda e: self.toplevel.quit()) | |
self.toplevel.bind('<F11>', self.toggle_fullscreen) # toggle this window fullscreen | |
self.toplevel.bind('f', self.toggle_fullscreen) # toggle this window fullscreen | |
self.toplevel.bind('<Escape>', self.do_fullscreen) | |
self.toplevel.bind('o', self.open_up) # open a second fullscreen window | |
self.blank_menu = Menu(self.toplevel) | |
self.menu = Menu(self.toplevel) | |
self.frame = Frame(self.toplevel) | |
self.frame.grid() | |
self.x_canvas = Canvas(self.frame) | |
self.x_canvas.pack(side=TOP) | |
self.frame.pack() | |
def open_up(self, event=None): | |
print('MainWindow.open_up') | |
self.second = FullscreenWindow(self.frame) | |
def toggle_fullscreen(self, event=None): | |
return self.do_fullscreen(event, not self.state) | |
def do_fullscreen(self, event=None, state=False): | |
print('MainWindow.do_fullscreen state={}'.format(state)) | |
self.state = state | |
self.toplevel.attributes('-fullscreen', self.state) | |
if self.state: | |
self.toplevel.config(menu=self.blank_menu) # self.blank_menu is a Menu object | |
else: | |
self.toplevel.config(menu=self.menu) # self.menu is your menu. | |
return 'break' | |
class FullscreenWindow(object): | |
def __init__(self, master=None): | |
self.state = False | |
self.toplevel = Toplevel(master) | |
self.toplevel.title('FullscreenWindow') | |
self.toplevel.bind('q', lambda e: self.toplevel.quit()) | |
self.toplevel.bind('f', lambda e: self.toplevel.destroy()) | |
self.toplevel.bind('<F11>', lambda e: self.toplevel.destroy()) | |
self.toplevel.bind('<Escape>', lambda e: self.toplevel.destroy()) | |
self.frame = Frame(self.toplevel) | |
self.frame.grid() | |
self.x_canvas = Canvas(self.frame) | |
self.x_canvas.pack(side=TOP) | |
self.frame.pack() | |
self.frame.after(10, self.fs) | |
def fs(self, event=None): | |
self.toplevel.attributes('-fullscreen', True) | |
if __name__ == '__main__': | |
w = MainWindow() | |
w.toplevel.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment