Added Config menu
This commit is contained in:
Generated
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -51,29 +51,58 @@ def on_key_press(key):
|
|||||||
|
|
||||||
|
|
||||||
def clear_focus(event):
|
def clear_focus(event):
|
||||||
"""Clears focus from entry when clicking anywhere else."""
|
"""Clears focus from entry when clicking anywhere else,
|
||||||
if event.widget != delay_entry:
|
except if clicking on an entry widget."""
|
||||||
|
if event.widget not in (delay_entry, hotkey_entry):
|
||||||
root.focus_set()
|
root.focus_set()
|
||||||
|
|
||||||
|
|
||||||
# GUI Setup
|
def open_config():
|
||||||
|
"""Opens the configuration menu by hiding the main frame and showing the config frame."""
|
||||||
|
main_frame.pack_forget()
|
||||||
|
config_frame.pack(fill=tk.BOTH, expand=True)
|
||||||
|
|
||||||
|
|
||||||
|
def close_config():
|
||||||
|
"""Closes the configuration menu, updates HOTKEY, and returns to the main UI."""
|
||||||
|
global HOTKEY
|
||||||
|
new_hotkey = hotkey_entry.get().strip()
|
||||||
|
if new_hotkey:
|
||||||
|
HOTKEY = KeyCode(char=new_hotkey[0])
|
||||||
|
start_button.config(text=f"Start ({HOTKEY.char.upper()})")
|
||||||
|
stop_button.config(text=f"Stop ({HOTKEY.char.upper()})")
|
||||||
|
main_hotkey_label.config(text=f"Press '{HOTKEY.char}' to Start/Stop")
|
||||||
|
config_frame.pack_forget()
|
||||||
|
main_frame.pack(fill=tk.BOTH, expand=True)
|
||||||
|
|
||||||
|
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.title("Fretux' Autoclicker")
|
root.title("Fretux' Autoclicker")
|
||||||
root.geometry("300x150")
|
root.geometry("300x200")
|
||||||
root.eval('tk::PlaceWindow . center')
|
root.eval('tk::PlaceWindow . center')
|
||||||
config_button = tk.Button(root, text="Configure")
|
main_frame = tk.Frame(root)
|
||||||
tk.Label(root, text="Delay between clicks (seconds):").pack()
|
main_frame.pack(fill=tk.BOTH, expand=True)
|
||||||
delay_entry = tk.Entry(root)
|
tk.Label(main_frame, text="Delay between clicks (seconds):").pack(pady=5)
|
||||||
delay_entry.pack()
|
delay_entry = tk.Entry(main_frame)
|
||||||
|
delay_entry.pack(pady=5)
|
||||||
delay_entry.insert(0, "0.5")
|
delay_entry.insert(0, "0.5")
|
||||||
tk.Label(root, text=f"Press '{HOTKEY.char}' to Start/Stop").pack()
|
main_hotkey_label = tk.Label(main_frame, text=f"Press '{HOTKEY.char}' to Start/Stop")
|
||||||
button_frame = tk.Frame(root)
|
main_hotkey_label.pack(pady=5)
|
||||||
|
button_frame = tk.Frame(main_frame)
|
||||||
button_frame.pack(pady=10)
|
button_frame.pack(pady=10)
|
||||||
start_button = tk.Button(button_frame, text=f"Start ({HOTKEY.char.upper()})", command=toggle_clicking, width=15)
|
start_button = tk.Button(button_frame, text=f"Start ({HOTKEY.char.upper()})", command=toggle_clicking, width=15)
|
||||||
stop_button = tk.Button(button_frame, text=f"Stop ({HOTKEY.char.upper()})", command=toggle_clicking, width=15)
|
stop_button = tk.Button(button_frame, text=f"Stop ({HOTKEY.char.upper()})", command=toggle_clicking, width=15)
|
||||||
start_button.pack(side=tk.LEFT, padx=5)
|
start_button.pack(side=tk.LEFT, padx=5)
|
||||||
stop_button.pack(side=tk.LEFT, padx=5)
|
stop_button.pack(side=tk.LEFT, padx=5)
|
||||||
config_button.pack(side=tk.TOP, padx=5)
|
config_button = tk.Button(main_frame, text="Configure", command=open_config)
|
||||||
|
config_button.pack(pady=5)
|
||||||
|
config_frame = tk.Frame(root)
|
||||||
|
tk.Label(config_frame, text="Configure HOTKEY").pack(pady=10)
|
||||||
|
hotkey_entry = tk.Entry(config_frame)
|
||||||
|
hotkey_entry.pack(pady=5)
|
||||||
|
hotkey_entry.insert(0, HOTKEY.char)
|
||||||
|
back_button = tk.Button(config_frame, text="Back", command=close_config)
|
||||||
|
back_button.pack(pady=10)
|
||||||
root.bind("<Button-1>", clear_focus)
|
root.bind("<Button-1>", clear_focus)
|
||||||
listener = Listener(on_press=on_key_press)
|
listener = Listener(on_press=on_key_press)
|
||||||
listener.start()
|
listener.start()
|
||||||
|
|||||||
Reference in New Issue
Block a user