在wxpython中用一个简单的按钮运行cmd命令

2024-04-26 02:27:08 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨伙计们,我做了一个简单的图形用户界面来运行一行代码,直到现在我通过命令运行命令

youtube网站-下载.pyhttp://www.youtube.com/——提取音频——音频格式mp3

现在我想用我的gui运行这个命令。在

我的图形用户界面是:

#!/usr/bin/python


import wx


APP_SIZE_X = 300
APP_SIZE_Y = 200

class MyButtons(wx.Dialog):
    def __init__(self, parent, id, title):
        wx.Dialog.__init__(self, parent, id, title, size=(APP_SIZE_X, APP_SIZE_Y))

        wx.Button(self, 1, 'Close', (50, 130))
        wx.Button(self, 2, 'Run', (150, 130), (110, -1))

        self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
        self.Bind(wx.EVT_BUTTON, self.OnRun, id=2)

        self.Centre()
        self.ShowModal()
        self.Destroy()

    def OnClose(self, event):
        self.Close(True)

    def OnRun(self,event):
        print "ok for now"


app = wx.App(0)
MyButtons(None, -1, 'buttons.py')
app.MainLoop()

我需要帮助,谢谢你的帮助。。。在


Tags: 命令selfidappsizetitleyoutubeinit
1条回答
网友
1楼 · 发布于 2024-04-26 02:27:08

您可以直接导入子进程并以这种方式调用脚本。像这样:

def OnRun(self,event):
    path = "/path/to/youtube-dl.py"
    url = "http://www.youtube.com/"
    subprocess.Popen(path, url, " extract-audio", " audio-format", "mp3")

有关详细信息,请参阅文档:http://docs.python.org/2/library/subprocess.html

相关问题 更多 >