我是这个python编程的新手。我正在尝试编写使tkinter按钮在raspberry pi 3中启动外部软件的代码。不幸的是,按下了按钮GUI,但是外部软件或程序没有启动。与按钮GUI链接的外部程序是kodi软件。按下GUI按钮是否可以启动kodi软件?
from tkinter import
import os
class Trying(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.button()
def button(self):
self.test = Button(self, text="Lauch", command="kodi")
self.test.grid()
def kodi():
os.startfile('/usr/share/applications/kodi.desktop')
root = Tk()
root.title("test kodi")
root.geometry("150x85")
app = Trying(root)
root.mainloop()
答案 0 :(得分:0)
这是您的固定代码:
from tkinter import *
import os
import subprocess
class Trying(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.button()
def button(self):
self.test = Button(self, text="Lauch", command=self.kodi)
self.test.grid()
def kodi(self):
print ("Button pressed")
subprocess.call(['kodi'])
root = Tk()
root.title("test kodi")
root.geometry("150x85")
app = Trying(root)
root.mainloop()
注意:
command=self.kodi
的按钮动作def kodi(self)