π§ Build a Modern FM Radio App in Python GUI | FuzzuTech Projects
Demo :
Click Video πππ
π‘ Features:
-
Full source code with folder structure
-
GUI tutorial using Tkinter
-
Includes 5 streaming radio stations
-
Stylish dark mode interface
-
Explanation of
ffplayusage -
Embedded YouTube Shorts for cross-traffic
Code :
import tkinter as tk
from tkinter import ttk
import subprocess
import psutil
import os
# FM Stations
FM_STATIONS = {
"π΅ Radio Paradise": "http://stream.radioparadise.com/mp3-192",
"πΆ BBC Radio 1": "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p",
"π§ 181.FM The Beat": "http://listen.181fm.com/181-beat_128k.mp3",
"πΈ Rock Radio": "http://streaming.radionomy.com/rockradio1",
"π Love Songs Radio": "https://cast1.torontocast.com:2210/stream",
}
class FMRadioApp:
def __init__(self, root):
self.root = root
self.root.title("π§ FuzzuTech FM Radio")
self.root.geometry("500x400")
self.root.configure(bg="#121212")
self.selected_station = tk.StringVar()
self.selected_station.set(list(FM_STATIONS.keys())[0])
self.player_process = None
title = tk.Label(root, text="π§ FuzzuTech FM Radio", font=("Helvetica", 20, "bold"),
bg="#121212", fg="#00FF99")
title.pack(pady=20)
style = ttk.Style()
style.theme_use("clam")
style.configure("TCombobox", fieldbackground="#333333", background="#444444", foreground="white")
self.station_menu = ttk.Combobox(root, values=list(FM_STATIONS.keys()),
textvariable=self.selected_station, font=("Arial", 12), width=35)
self.station_menu.pack(pady=10)
play_btn = tk.Button(root, text="▶ Play", command=self.play_radio,
font=("Arial", 14), bg="#00CC66", fg="white", width=12)
play_btn.pack(pady=10)
stop_btn = tk.Button(root, text="⏹ Stop", command=self.stop_radio,
font=("Arial", 14), bg="#CC0033", fg="white", width=12)
stop_btn.pack(pady=10)
info = tk.Label(root, text="π’ FFmpeg required (ffplay)", font=("Arial", 10),
bg="#121212", fg="#AAAAAA")
info.pack(pady=5)
def play_radio(self):
self.stop_radio() # Ensures no duplicate play
url = FM_STATIONS[self.selected_station.get()]
self.player_process = subprocess.Popen(
["ffplay", "-nodisp", "-autoexit", "-loglevel", "quiet", url],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
def stop_radio(self):
if self.player_process and self.player_process.poll() is None:
try:
# Kill child processes properly
parent = psutil.Process(self.player_process.pid)
for child in parent.children(recursive=True):
child.kill()
parent.kill()
except Exception as e:
print("Error stopping process:", e)
finally:
self.player_process = None
if __name__ == "__main__":
root = tk.Tk()
app = FMRadioApp(root)
root.mainloop()
Comments
Post a Comment