0
我想要一个文件在我的tkinter GUI中的按钮上打开。但是,声音文件在我的程序运行时播放(如同马上)并且在按下按钮时不起作用。这里是我的代码:如何使用Tkinter按钮控制文件打开?
####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()
有我在我的代码犯了一个错误还是我需要添加别的东西来获取声音时按下按钮的工作,而不是在脚本运行时?
感谢
除非你不需要做你的对象什么了,其中情况下,不要将它们分配给一个变量。我总是用'Labels'作为我的'Entry'字段。 'date = StringVar(); e_date = ttk.Entry(根,textvariable =日期); e_date.grid(行= 1,列= 2); ttk.Label(root,text =“Date:”)。grid(row = 1,column = 1' –
非常感谢!这解决了我遇到的问题,额外的建议非常感谢! – Snubb