Miscellaneous scripts
This repository contains miscellaneous scripts that does not fit in one repository, yet I will use them sometimes for my personal use. Note that some of the scripts might contain hardcoded paths and opinionated presets, and you are advised to inspect them before actually using.
Loading...
Searching...
No Matches
troll.py
Go to the documentation of this file.
1import logging
2import tkinter
3import tkinter.ttk
4from typing import Tuple
5
6
7def centre_coordinate(root: tkinter.Tk, width: int, height: int,
8 is_root_window: bool = True) -> Tuple[int, int, int, int]:
9 # code from utils.py (spam bot gui project)
10 # USAGE: root.geometry(f"{width}x{height}+{x}+{y}")
11 # where width and height are the desired dimensions
12 if is_root_window: # separate handling of window coordinate for root window
13 # get device screen resolution
14 root_width, root_height = root.winfo_screenwidth(), root.winfo_screenheight()
15 return width, height, int(root_width / 2 - width / 2), int(root_height / 2 - height / 2)
16 # root.window.update_idletasks()
17 base_width = root.winfo_width()
18 base_height = root.winfo_height()
19 # -20: modifier of the [-] [X] space
20 height_coord = root.winfo_rooty() + (base_height - height) / 2 - 20
21 width_coord = root.winfo_rootx() + (base_width - width) / 2
22 logging.debug(f"Coordinates: width={width}, height={height},"
23 f"x={int(width_coord)}, y={int(height_coord)}")
24 return width, height, int(width_coord), int(height_coord)
25
26
27def puts_text(window: tkinter.Tk, width, height: int, pb_main: tkinter.ttk.Progressbar) -> None:
28 pb_main.destroy()
29 msg_gay = tkinter.Label(window, text="You are genius", font=("Segoe UI Light", 30))
30 msg_gay.pack()
31
32 # confirmation button
33 button_ok = tkinter.Button(window, text="Ok", command=window.destroy, bd=2.3)
34 button_ok.place(height=30, width=65, x=width / 2 - 65 / 2, y=height - 40)
35 window.update()
36
37
38def main(width, height: int) -> None:
39 # window is the root window of tkinter
40 window = tkinter.Tk()
41 # window title
42 window.title("Important Message")
43
44 # Loading progressbar animation
45 pb_main = tkinter.ttk.Progressbar(window, orient=tkinter.HORIZONTAL,
46 length=200, maximum=1000, mode='indeterminate')
47 # x=50 for middle progressbar
48 pb_main.place(height=30, x=50, y=20)
49 pb_main.start(1)
50
51 # put main text into window
52 window.after(3000, puts_text, window, width, height, pb_main)
53
54 # setup of miscellaneous stuffs
55 window.geometry("%sx%s+%s+%s" % centre_coordinate(window, width, height))
56 window.focus_force()
57 window.resizable()
58 window.update_idletasks()
59 window.mainloop()
60
61
62def run() -> None:
63 # run the main function
64 main(300, 100)
65
66
67# prevent code running as imported package
68if __name__ == '__main__':
69 run()
Definition main.py:1
Tuple[int, int, int, int] centre_coordinate(tkinter.Tk root, int width, int height, bool is_root_window=True)
Definition troll.py:8
None puts_text(tkinter.Tk window, width, int height, tkinter.ttk.Progressbar pb_main)
Definition troll.py:27
None run()
Definition troll.py:62