简体   繁体   English

Tkinter打开一个外部exe文件

[英]Tkinter open an external exe file

I'm trying to setup an icon which, once pressed, open the file "sqlite3.exe" in order to manage a small database. 我正在尝试设置一个图标,一旦按下该图标,将打开文件“ sqlite3.exe”以管理小型数据库。 If I input this from the command line: 如果我从命令行输入:

os.system("sqlite3.exe")

the sqlite3 window is opened without problem, but if I embend the command in a Tk interface i'm not able to see the sqlite3 window (maybe it closes without trace?). sqlite3窗口打开没有问题,但是如果我将命令嵌入到Tk界面中,我将看不到sqlite3窗口(也许它关闭而没有跟踪?)。 I tried both os.system and subprocess with the same result. 我尝试了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()

from Tkinter import * import os 从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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM