小编MrC*_*ude的帖子

需要 1 个位置参数,但给出了 2 个

我想运行一个命令行工具以在单独的函数中运行并传递给按钮单击此程序的附加命令,但每次我都将其作为响应。

需要 1 个位置参数,但给出了 2 个

from tkinter import *
import subprocess


class StdoutRedirector(object):
    def __init__(self,text_widget):
        self.text_space = text_widget

    def write(self,string):
        self.text_space.insert('end', string)
        self.text_space.see('end')

class CoreGUI(object):
    def __init__(self,parent):
        self.parent = parent
        self.InitUI()

        button = Button(self.parent, text="Check Device", command= self.adb("devices"))
        button.grid(column=0, row=0, columnspan=1)

    def InitUI(self):
        self.text_box = Text(self.parent, wrap='word', height = 6, width=50)
        self.text_box.grid(column=0, row=10, columnspan = 2, sticky='NSWE', padx=5, pady=5)
        sys.stdout = StdoutRedirector(self.text_box)

    def adb(self, **args):
        process = subprocess.Popen(['adb.exe', args], stdout=subprocess.PIPE, shell=True)
        print(process.communicate())
        #return x.communicate(stdout)


root = Tk()
gui = …
Run Code Online (Sandbox Code Playgroud)

python subprocess tkinter popen python-3.x

6
推荐指数
1
解决办法
7万
查看次数

标签 统计

popen ×1

python ×1

python-3.x ×1

subprocess ×1

tkinter ×1