[英]Running an external program through a tkinter button in python
我是編程新手,實際上只為學校項目這樣做。 我試圖制作一個具有一系列按鈕的GUI,按下該按鈕將運行特定的模擬器。 當我嘗試運行此程序時,出現錯誤消息“ z26”未定義。 我不太確定如何實際定義它。
from tkinter import *
import os
class Application(Frame):
def __init__(self, master):
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
self._button = Button(self, text = "Atari", command = self._openFile)
self._button.grid()
def _openFile(self):
os.startfile(z26.exe)
root = Tk()
root.title("Arcade")
root.geometry("200x85")
app = Application(root)
root.mainloop()
問題是您將x26.exe用作文字,並且對其進行了評估,就好像它是Python程序本身的一部分一樣。
而是將路徑用引號引起來,使其成為字符串:
os.startfile('path/z26.exe')
另請參見Python文檔os.startfile(path [,operation]) 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.