Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import filedialog
- from tkinter import ttk # Import ttk module for themed scrollbar
- import vlc
- def open_radio():
- selected_radio = listbox.curselection()
- if selected_radio:
- index = int(selected_radio[0])
- selected_radio_title = radio_titles[index]
- selected_radio_url = radio_urls[index]
- textfield.delete(1.0, tk.END)
- textfield.insert(tk.END, selected_radio_title)
- media = instance.media_new(selected_radio_url)
- player.set_media(media)
- player.play()
- def load_radios():
- file_path = filedialog.askopenfilename(filetypes=[("M3U files", "*.m3u")])
- if file_path:
- with open(file_path, 'r', encoding='utf-8') as f:
- global radio_titles, radio_urls
- radio_titles, radio_urls = [], []
- for line in f:
- if line.startswith('#EXTINF:'):
- title = line.split(',')[-1].strip()
- radio_titles.append(title)
- elif line.strip() and not line.startswith('#'):
- radio_urls.append(line.strip())
- for title in radio_titles:
- listbox.insert(tk.END, title)
- # Create main window
- root = tk.Tk()
- root.title("Najeeb Radio Player")
- root.geometry("600x230")
- # Define colors
- background_color = 'lightgreen'
- text_color = '#FFFFFF'
- button_color = '#4CAF50'
- button_text_color = '#FFFFFF'
- root.config(bg=background_color)
- # Create VLC instance and player
- instance = vlc.Instance('--no-xlib')
- player = instance.media_player_new()
- # Create and pack widgets
- textfield = tk.Text(root, height=1, width=100)
- textfield.pack(pady=10, padx=10)
- listbox_frame = tk.Frame(root)
- listbox_frame.pack(padx=10, pady=5)
- scrollbar = ttk.Scrollbar(listbox_frame, orient=tk.VERTICAL)
- listbox = tk.Listbox(listbox_frame, selectmode=tk.SINGLE, height=6, width=48, font=("Time New Roman", 16, "bold"), yscrollcommand=scrollbar.set)
- scrollbar.config(command=listbox.yview)
- scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
- listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
- load_button = tk.Button(root, text="Load Radios", command=load_radios, bg=button_color, fg=button_text_color)
- load_button.pack(side=tk.LEFT, padx=10)
- play_button = tk.Button(root, text="Play Radio", command=open_radio, bg=button_color, fg=button_text_color)
- play_button.pack(side=tk.RIGHT, padx=10)
- root.mainloop()
Add Comment
Please, Sign In to add comment