-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
36 lines (29 loc) · 1.06 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import tkinter as tk
from tkinter import filedialog
import subprocess
class VideoPlayer:
def __init__(self, root):
self.root = root
self.root.title("Video Player")
self.video_path = ""
self.frame = tk.Frame(root)
self.frame.pack(padx=10, pady=10)
self.browse_button = tk.Button(self.frame, text="Browse", command=self.browse_video)
self.browse_button.pack()
def browse_video(self):
self.video_path = filedialog.askopenfilename(filetypes=[("Video files", "*.mp4 *.avi *.mkv")])
if self.video_path:
self.play_video()
def play_video(self):
if self.video_path:
if os.name == 'nt': # Windows
os.startfile(self.video_path)
elif os.name == 'posix': # Linux or macOS
subprocess.Popen(['xdg-open', self.video_path])
else:
print("Unsupported operating system.")
if __name__ == "__main__":
root = tk.Tk()
app = VideoPlayer(root)
root.mainloop()