Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 40f455e

Browse files
Add files via upload (#165)
1 parent 7b99f6a commit 40f455e

File tree

2 files changed

+189
-0
lines changed

2 files changed

+189
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import os
2+
import pygame
3+
import tkinter as tk
4+
from tkinter import filedialog
5+
from tkinter import ttk
6+
7+
# Initialize pygame mixer
8+
pygame.mixer.init()
9+
10+
# Function to list music files in a directory
11+
def list_music_files(directory):
12+
music_files = []
13+
for root, _, files in os.walk(directory):
14+
for file in files:
15+
if file.endswith((".mp3", ".wav")):
16+
music_files.append(os.path.join(root, file))
17+
return music_files
18+
19+
# Function to play music
20+
def play_music():
21+
selected_item = music_listbox.curselection()
22+
if selected_item:
23+
index = int(selected_item[0])
24+
pygame.mixer.music.load(music_files[index])
25+
pygame.mixer.music.play()
26+
27+
# Function to pause music
28+
def pause_music():
29+
pygame.mixer.music.pause()
30+
31+
# Function to resume music
32+
def resume_music():
33+
pygame.mixer.music.unpause()
34+
35+
# Function to stop music
36+
def stop_music():
37+
pygame.mixer.music.stop()
38+
39+
# Function to open a directory dialog and set the music directory
40+
def choose_directory():
41+
global music_directory
42+
music_directory = filedialog.askdirectory()
43+
music_files = list_music_files(music_directory)
44+
music_listbox.delete(0, tk.END)
45+
for file in music_files:
46+
music_listbox.insert(tk.END, os.path.basename(file))
47+
48+
# Create a tkinter window
49+
root = tk.Tk()
50+
# Adjust size
51+
root.geometry("420x300")
52+
53+
# set minimum window size value
54+
root.minsize(420, 300)
55+
56+
# set maximum window size value
57+
root.maxsize(420, 300)
58+
root.title("Video Player")
59+
root.title("Music Player")
60+
61+
# Create and configure a frame for buttons
62+
button_frame = ttk.Frame(root)
63+
button_frame.grid(row=1, column=0, padx=20, pady=10)
64+
65+
# Create buttons
66+
play_button = ttk.Button(button_frame, text="Play", command=play_music)
67+
pause_button = ttk.Button(button_frame, text="Pause", command=pause_music)
68+
resume_button = ttk.Button(button_frame, text="Resume", command=resume_music)
69+
stop_button = ttk.Button(button_frame, text="Stop", command=stop_music)
70+
71+
# Grid layout for buttons
72+
play_button.grid(row=0, column=0, padx=10)
73+
pause_button.grid(row=0, column=1, padx=10)
74+
resume_button.grid(row=0, column=2, padx=10)
75+
stop_button.grid(row=0, column=3, padx=10)
76+
77+
# Create a frame for the music list
78+
list_frame = ttk.Frame(root)
79+
list_frame.grid(row=0, column=0, padx=20, pady=10)
80+
81+
# Create a listbox to display music files
82+
music_listbox = tk.Listbox(list_frame, selectmode=tk.SINGLE, width=50)
83+
music_listbox.pack()
84+
85+
# Create a button to choose the music directory
86+
choose_button = ttk.Button(list_frame, text="Choose Music Directory", command=choose_directory)
87+
choose_button.pack()
88+
89+
# Initialize the music directory
90+
music_directory = ""
91+
92+
# Run the tkinter main loop
93+
root.mainloop()
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import os
2+
import pygame
3+
import tkinter as tk
4+
from tkinter import filedialog
5+
from tkinter import ttk
6+
7+
# Initialize pygame
8+
pygame.init()
9+
10+
# Function to list video files in a directory
11+
def list_video_files(directory):
12+
video_files = []
13+
for root, _, files in os.walk(directory):
14+
for file in files:
15+
if file.endswith((".mp4", ".avi", ".mkv")):
16+
video_files.append(os.path.join(root, file))
17+
return video_files
18+
19+
# Function to play video
20+
def play_video():
21+
selected_item = video_listbox.curselection()
22+
if selected_item:
23+
index = int(selected_item[0])
24+
video = pygame.movie.Movie(video_files[index])
25+
video.set_display(video_display)
26+
video.play()
27+
28+
# Function to pause video
29+
def pause_video():
30+
pygame.mixer.music.pause()
31+
32+
# Function to resume video
33+
def resume_video():
34+
pygame.mixer.music.unpause()
35+
36+
# Function to stop video
37+
def stop_video():
38+
pygame.mixer.music.stop()
39+
40+
# Function to open a directory dialog and set the video directory
41+
def choose_directory():
42+
global video_directory
43+
video_directory = filedialog.askdirectory()
44+
video_files = list_video_files(video_directory)
45+
video_listbox.delete(0, tk.END)
46+
for file in video_files:
47+
video_listbox.insert(tk.END, os.path.basename(file))
48+
49+
# Create a tkinter window
50+
root = tk.Tk()
51+
# Adjust size
52+
root.geometry("420x300")
53+
54+
# set minimum window size value
55+
root.minsize(420, 300)
56+
57+
# set maximum window size value
58+
root.maxsize(420, 300)
59+
root.title("Video Player")
60+
61+
# Create and configure a frame for buttons
62+
button_frame = ttk.Frame(root)
63+
button_frame.grid(row=1, column=0, padx=20, pady=10)
64+
65+
# Create buttons
66+
play_button = ttk.Button(button_frame, text="Play", command=play_video)
67+
pause_button = ttk.Button(button_frame, text="Pause", command=pause_video)
68+
resume_button = ttk.Button(button_frame, text="Resume", command=resume_video)
69+
stop_button = ttk.Button(button_frame, text="Stop", command=stop_video)
70+
71+
# Grid layout for buttons
72+
play_button.grid(row=0, column=0, padx=10)
73+
pause_button.grid(row=0, column=1, padx=10)
74+
resume_button.grid(row=0, column=2, padx=10)
75+
stop_button.grid(row=0, column=3, padx=10)
76+
77+
# Create a frame for the video list
78+
list_frame = ttk.Frame(root)
79+
list_frame.grid(row=0, column=0, padx=20, pady=10)
80+
81+
# Create a listbox to display video files
82+
video_listbox = tk.Listbox(list_frame, selectmode=tk.SINGLE, width=50)
83+
video_listbox.pack()
84+
85+
# Create a button to choose the video directory
86+
choose_button = ttk.Button(list_frame, text="Choose Video Directory", command=choose_directory)
87+
choose_button.pack()
88+
89+
# Initialize the video directory
90+
video_directory = ""
91+
92+
# Create a Pygame display for video playback
93+
video_display = pygame.display.set_mode((640, 480))
94+
95+
# Run the tkinter main loop
96+
root.mainloop()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /