【发布时间】:2014-02-13 02:17:26
【问题描述】:
我想在我的 tkinter gui 中按下按钮打开一个文件。但是,声音文件在我的程序运行时播放(如立即运行)并且在按下按钮时不起作用。这是我的代码:
####Imports
import os
import sys
from tkinter import *
####definitions
def blackobj ():
from os import startfile
startfile ('simon_objection.mp3')
####Window
mGui = Tk()
mGui.geometry ('1280x720+100+50')
mGui.title ('Gui App')
mGui.configure(background='blue')
####Labels
#Title
wlabel = Label(text = "Welcome to the Ace Attorney Soundboard!", font = 'georgia',fg ='white', bg = 'blue').place(x=0,y=0)
objectionheader = Label (text = 'Objections:', font = 'georgia', fg = 'white', bg = 'blue',).place (x=0,y=45)
####Buttons
objblackquill = Button (mGui, text = 'Blackquill', font = 'georgia', command =blackobj()).place (x=0,y=75)
mGui.mainloop()
我的代码是否有错误,或者我是否需要添加其他内容才能在按下按钮而不是脚本运行时发出声音?
谢谢
【问题讨论】:
标签: python button user-interface tkinter