Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_fullscreen_toggle.py
- import tkinter as tk
- import ctypes
- import time
- # Define ctypes structures and functions
- class POINT(ctypes.Structure):
- _fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)]
- def get_xy():
- point = POINT()
- ctypes.windll.user32.GetCursorPos(ctypes.byref(point))
- return point.x, point.y
- def gui_update(event):
- global cx, cy, cw, ch
- # get the root position and height
- if not fullscreen:
- cx = root.winfo_x()
- cy = root.winfo_y()
- cw = root.winfo_width()
- ch = root.winfo_height()
- def make_fullscreen():
- global fullscreen, width, height
- fullscreen = True
- fullscreen_button.place_forget()
- root.overrideredirect(True)
- width = root.winfo_screenwidth()
- height = root.winfo_screenheight()
- canvas.config(width=width, height=height)
- fullscreen_title_bar()
- def kill_fullscreen():
- global fullscreen
- fullscreen = False
- fs_btn()
- root.overrideredirect(False)
- root.geometry(f"{cx}x{cy}+{cw}+{ch}")
- canvas.config(width=cw, height=ch)
- def fullscreen_title_bar():
- global title_bar
- if y < 40:
- if not title_bar:
- title_bar = 1
- root.overrideredirect(False)
- root.geometry("%dx%d+-8+0" % (width, height-72))
- else:
- if title_bar:
- title_bar = 0
- root.overrideredirect(True)
- root.geometry("%dx%d+-0+0" % (width, height))
- def toggle_title_bar():
- if -out > x or x > cw + out or -out > y or y > ch + out + 20:
- canvas.config(bg='darkred')
- root.overrideredirect(True)
- fullscreen_button.place_forget()
- else:
- canvas.config(bg='darkgreen')
- root.overrideredirect(False)
- fs_btn()
- ww = 300
- hh = 300
- cx = 0
- cy = 0
- title_bar = 1
- width = height = 0
- fullscreen = 0
- root = tk.Tk()
- root.geometry("%dx%d+100+100" % (ww, hh))
- canvas = tk.Canvas(root, width=ww, height=hh, bg='darkgreen')
- canvas.pack()
- # Create a fullscreen button widget
- fullscreen_button = tk.Button(canvas, text="Full Screen", command=make_fullscreen, bg="gray90")
- def fs_btn():
- fullscreen_button.place(x=5, y=5)
- fs_btn()
- gui_update(0)
- root.bind("<Configure>", gui_update)
- out = 50
- while 1:
- x, y = get_xy()
- if not fullscreen:
- x = (x - cx)
- y = (y - cy)
- toggle_title_bar()
- else:
- fullscreen_title_bar()
- canvas.update()
- 0/0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement