import subprocess from time import sleep import tkinter as ttk import _detectsong as ds root = ttk.Tk() root.title("Radio Controller") # root.geometry("1280x400") root.geometry("800x400") root.attributes("-topmost", True) # sv_ttk.use_dark_theme() st1_button = ttk.Button(root, text="94.7M", borderwidth=0, command=lambda: tune(94.7)) st2_button = ttk.Button(root, text="96.9M", borderwidth=0, command=lambda: tune(96.9)) st3_button = ttk.Button(root, text="98.5M", borderwidth=0, command=lambda: tune(98.5)) st4_button = ttk.Button(root, text="100.5M", borderwidth=0, command=lambda: tune(100.5)) st5_button = ttk.Button(root, text="101.1M", borderwidth=0, command=lambda: tune(101.1)) st6_button = ttk.Button(root, text="102.5M", borderwidth=0, command=lambda: tune(102.5)) st7_button = ttk.Button(root, text="103.5M", borderwidth=0, command=lambda: tune(103.5)) st8_button = ttk.Button(root, text="106.5M", borderwidth=0, command=lambda: tune(106.5)) st9_button = ttk.Button(root, text="107.9M", borderwidth=0, command=lambda: tune(107.9)) exit_button = ttk.Button(root, text="Exit", command=lambda: on_close(True)) volume_slider = ttk.Scale(root, from_=0, to=100, orient=ttk.HORIZONTAL) stop_button = ttk.Button(root, text="Stop", command=lambda: on_close()) # root.protocol("WM_DELETE_WINDOW", lambda e: on_close()) st1_button.grid(row=0, column=0) st2_button.grid(row=0, column=1) st3_button.grid(row=0, column=2) st4_button.grid(row=0, column=3) st5_button.grid(row=0, column=4) st6_button.grid(row=0, column=5) st7_button.grid(row=0, column=6) st8_button.grid(row=0, column=7) st9_button.grid(row=0, column=8) exit_button.grid(row=1, column=0) volume_slider.grid(row=1, column=1, columnspan=3) stop_button.grid(row=1, column=4) # Input file path input_file = "fm_data.raw" tuner = None player = None def tune(station): global tuner global player # random_num = random.randint(0, 1000000) # print(random_num) if tuner is not None: tuner.kill() sleep(3) if player is not None: player.kill() tuner = subprocess.Popen(["rx_fm", "-f", f"{station}M", "-M", "fm", "-s", "170k", "-A", "fast", "-l", "0", "-E", "deemp", "-E", "wav", "-d", "driver=hackrf", input_file]) sleep(2.5) player = subprocess.Popen(["C:\\Program Files\\VideoLAN\\VLC\\vlc", "--play-and-exit", "C:\\Users\\spong\\Documents\\Python Programs\\PySDR\\FM Radio\\fm_data.raw"]) def on_close(halt=False): if tuner: tuner.kill() if player: player.kill() if halt == True: exit() def adj_vol(): pass try: root.mainloop() except KeyboardInterrupt: on_close()