iT邦幫忙

0

python關於 wx & subprocess 的語法請益

  • 分享至 

  • twitterImage

Hi 大家好
最近在學習實作python
這是一段網路上看到的程式碼並做了些小修改
運用wx & subprocess 模組後 能點一個按鈕同時叫出 兩個cmd 視窗
一個做wget http的,一個https的
但我程式碼這樣改了之後,只會呼叫http的,
想詢問各位大大這段程式碼應該如何改可以同時教出兩個cmd視窗並做不同的呼叫
謝謝各位/images/emoticon/emoticon41.gif

b1=wx.Button(panel, label='wget https')
b1.SetFont(font)
self.Bind(wx.EVT_BUTTON,lambda _:subprocess.Popen('cmd /k tools\\wget https://'+tc.GetValue().replace(':',' ')),b1)
self.Bind(wx.EVT_BUTTON,lambda _:subprocess.Popen('cmd /k tools\\wget http://'+tc.GetValue().replace(':',' ')),b1)
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
froce
iT邦大師 1 級 ‧ 2021-01-08 15:29:00
最佳解答
def openCmd():
    subprocess.Popen('cmd /k tools\\wget http://'+tc.GetValue().replace(':',' '))
    subprocess.Popen('cmd /k tools\\wget https://'+tc.GetValue().replace(':',' '))

b1=wx.Button(panel, label='wget https')
b1.SetFont(font)
self.Bind(wx.EVT_BUTTON,openCmd,b1)

這樣試試,因為我不知道你 tc 變數是在什麼scope下,所以應該會跳出 tc not found 之類的 error。

你bind 2次當然會只有第2次會生效啊...

然後wx我不熟,如果還有進階的問題不要問我。

我要發表回答

立即登入回答