[英]Tkinter open an external exe file
我正在嘗試設置一個圖標,一旦按下該圖標,將打開文件“ sqlite3.exe”以管理小型數據庫。 如果我從命令行輸入:
os.system("sqlite3.exe")
sqlite3窗口打開沒有問題,但是如果我將命令嵌入到Tk界面中,我將看不到sqlite3窗口(也許它關閉而沒有跟蹤?)。 我嘗試了os.system和子進程,結果相同。
from Tkinter import *
import os
import threading
import subprocess
class Application(object):
def __init__(self, root):
super(Application, self).__init__()
self.root = root
self.main_container = Frame(self.root)#, bg="bisque")
self.main_container.pack(side=TOP, fill="both", expand='yes')
self.button_1 = Button(self.main_container, text = "Os", relief=RAISED, command = lambda: self.os_open())
self.button_1.pack()
self.button_2 = Button(self.main_container, text = "Subprocess", relief=RAISED, command = lambda: self.sub_open())
self.button_2.pack()
def os_open(self):
os.system("sqlite3.exe")
def sub_open(self):
exe = "sqlite3.exe"
process = subprocess.Popen(exe, stdout=subprocess.PIPE)
process.wait()
root = Tk()
app = Application(root)
root.mainloop()
從Tkinter導入*導入os
class App:
def __init__(self, master):
self.frame = Frame(master)
self.b = Button(self.frame, text = 'Open', command = self.openFile)
self.b.grid(row = 1)
self.frame.grid()
def openFile(self):
os.startfile(_filepath_)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.