Ich möchte ein Befehlszeilenprogramm ausführen, um in einer separaten Funktion auszuführen und an die Schaltfläche weitergeleitet klicken Sie auf den zusätzlichen Befehl für dieses Programm, aber jedes Mal bekomme ich dies als eine Antwort.dauert 1 Positionsargument aber 2 wurden gegeben
dauert 1 Positions Argument aber 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 = CoreGUI(root)
root.mainloop()
der Fehler
Traceback (most recent call last):
File "C:/Users/Maik/PycharmProjects/Lernen/subprocessExtra.py", line 33, in <module>
gui = CoreGUI(root)
File "C:/Users/Maik/PycharmProjects/Lernen/subprocessExtra.py", line 18, in __init__
button = Button(self.parent, text="Check Device", command= self.adb("devices"))
TypeError: adb() takes 1 positional argument but 2 were given
Exception ignored in: <__main__.StdoutRedirector object at 0x013531B0>
AttributeError: 'StdoutRedirector' object has no attribute 'flush'
Process finished with exit code 1
kann mir einige Körper helfen
gegeben wurden es ist etwas falsch mit ** args
Können wir den genauen Fehler zu sehen, und die spezifische Linie, wo es passiert – Li357
'Traceback (jüngste Aufforderung zuletzt): Datei „*/subprocessExtra.py ", Zeile 33, in gui = CoreGUI (root) Datei" */subprocessExtra.py ", Zeile 18, in __init__ button = Schaltfläche (self.parent, text =" Check Device ", command = self.adb ("devices")) TypeError: adb() benötigt 1 Positionsargument, 2 hat Ausnahme ignoriert in: <__ Haupt __ StdoutRedirector Objekt bei 0x013531B0.> Attribute: 'StdoutRedirector' Objekt kein Attribut 'bündig' hat Prozess mit Exit-Code beendet 1 " –
MrChaosBude
, die in der Frage sein sollte: ^) – Li357