gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
Write Python tkinter program that displays window with label "Turmoil Launcher" and runs…
- User
Write Python tkinter program that displays window with label "Turmoil Launcher" and runs firefox if pressed F key, or runs brave if pressed B key, or runs dia if pressed D key.
- Assistant
Certainly! You can create a simple Tkinter application that listens for specific key presses and launches the corresponding application (Firefox, Brave, or Dia). Below is the Python code that accomplishes this:
import tkinter as tk import subprocess def run_firefox(event): """Function to run Firefox when 'F' key is pressed.""" try: subprocess.Popen(['firefox']) except Exception as e: print(f"Error launching Firefox: {e}") def run_brave(event): """Function to run Brave when 'B' key is pressed.""" try: subprocess.Popen(['brave']) except Exception as e: print(f"Error launching Brave: {e}") def run_dia(event): """Function to run Dia when 'D' key is pressed.""" try: subprocess.Popen(['dia']) except Exception as e: print(f"Error launching Dia: {e}") # Create the main window root = tk.Tk() root.title("Turmoil Launcher") root.geometry("300x100") # Create a label label = tk.Label(root, text="Turmoil Launcher", font=("Helvetica", 14)) label.pack(expand=True) # Bind key events root.bind('<KeyPress-f>', run_firefox) root.bind('<KeyPress-b>', run_brave) root.bind('<KeyPress-d>', run_dia) # Start the Tkinter main loop root.mainloop()