海量编程文章、技术教程与实战案例

网站首页 > 技术文章 正文

小白用DeepSeek+Python编写软件

yimeika 2025-06-02 21:44:48 技术文章 7 ℃

周末无事,用DeepSeek生成全部代码,写了一个mp3音乐播放器,几分钟搞定,DeepSeek确实太强大了。我的提示语是这么写的:“请用Python语言写一个音乐播放器,支持常见音乐格式,我是Python小白,请写出全部代码,不需要我修改即可运行。”不到1分钟,立刻给出了全部代码:

import tkinter as tk

from tkinter import filedialog

import pygame

class MusicPlayer:

def __init__(self, root):

self.root = root

self.root.title("Music Player")

self.root.geometry("300x200")

self.label = tk.Label(root, text="Music Player")

self.label.pack(pady=10)

self.open_button = tk.Button(root, text="Open Music File", command=self.open_file)

self.open_button.pack(pady=5)

self.play_button = tk.Button(root, text="Play", command=self.play_music, state=tk.DISABLED)

self.play_button.pack(pady=5)

self.pause_button = tk.Button(root, text="Pause", command=self.pause_music, state=tk.DISABLED)

self.pause_button.pack(pady=5)

self.stop_button = tk.Button(root, text="Stop", command=self.stop_music, state=tk.DISABLED)

self.stop_button.pack(pady=5)

self.file_path = None

self.music = None

def open_file(self):

self.file_path = filedialog.askopenfilename(filetypes=[("MP3 files", "*.mp3")])

if self.file_path:

self.play_button.config(state=tk.NORMAL)

self.pause_button.config(state=tk.NORMAL)

self.stop_button.config(state=tk.NORMAL)

def play_music(self):

if self.music:

self.music.stop()

self.music = pygame.mixer.music.load(self.file_path)

pygame.mixer.music.play()

def pause_music(self):

pygame.mixer.music.pause()

def stop_music(self):

pygame.mixer.music.stop()

if __name__ == "__main__":

pygame.mixer.init()

root = tk.Tk()

app = MusicPlayer(root)

root.mainloop()

运行后界面如下,可以正常播放音乐,太强大了。


最近发表
标签列表