我试图制作,按下按钮后,我会获得标签中显示的信息,但是,我似乎无法使标签显示在GUI中。当我按下" Vartotojo informacija>时,我会收到错误。输入名称并按" rodyti informacija"我在这一行w.pack(LEFT)
上得到错误(应该是第95行):
完整追溯:
'id' is not recognized as an internal or external command,
operable program or batch file.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python\lib\lib-tk\Tkinter.py", line 1542, in __call__
return self.func(*args)
File "tkinter-label-not-showing-after-button-pressed.py", line 96, in <lambda>
myg1 = Button(virsus, text="Rodyti informacija", command=lambda: gauti())
File "tkinter-label-not-showing-after-button-pressed.py", line 103, in gauti
w.pack(LEFT)
File "C:\Python\lib\lib-tk\Tkinter.py", line 1946, in pack_configure
+ self._options(cnf, kw))
File "C:\Python\lib\lib-tk\Tkinter.py", line 1169, in _options
for k, v in cnf.items():
AttributeError: 'str' object has no attribute 'items'
我的代码:
from Tkinter import *
import tkMessageBox
from sys import version_info
import subprocess
root = Tk()
root.title("Administravimas")
virsus = Frame(root)
virsus.pack()
apacia = Frame(root)
apacia.pack(side=BOTTOM)
def filtras():
root = Tk()
root.title("Filtravimas pagal uzklausa")
root.geometry("300x100")
tekstas = Text(root, height=1, width=15)
tekstas.pack(side=TOP)
virsus = Frame(root)
virsus.pack()
apacia = Frame(root)
apacia.pack(side=BOTTOM)
myg1 = Button(virsus, text="Filtruoti", command=lambda: gauti())
myg1.pack(side=BOTTOM)
def gauti():
imti=tekstas.get("1.0", "end-1c")
subprocess.call("grep -i '{imti}' /var/log/syslog > "
"logai/uzklausa/$(date +%d_%m_%Y.txt)".format(imti=imti),
shell=True)
def vartotojas():
root = Tk()
root.title("Filtravimas pagal vartotoju prisijungimus")
root.geometry("300x100")
tekstas = Text(root, height=1, width=15)
tekstas.pack(side=TOP)
virsus = Frame(root)
virsus.pack()
apacia = Frame(root)
apacia.pack(side=BOTTOM)
myg1 = Button(virsus, text="Filtruoti", command=lambda: gauti())
myg1.pack(side=BOTTOM)
def gauti():
imti = tekstas.get("1.0", "end-1c")
subprocess.call("grep -i '{imti}' /var/log/auth.log > "
"logai/vartotojai/$(date +%d_%m_%Y.txt)".format(imti=imti),
shell=True)
def portas():
root = Tk()
root.title("Atidaryti/uzdaryti portus")
root.geometry("300x100")
virsus = Frame(root)
virsus.pack()
apacia = Frame(root)
apacia.pack(side=BOTTOM)
myg1 = Button(virsus, text="Atidaryti porta")
myg2 = Button(virsus, text="Uzdaryti porta")
myg1.pack(side=LEFT)
myg2.pack(side=LEFT)
root.mainloop()
def administ():
root = Tk()
root.title("Administrouti vartotojus")
root.geometry("400x100")
virsus = Frame(root)
virsus.pack()
apacia = Frame(root)
apacia.pack(side=BOTTOM)
myg1 = Button(virsus, text="Kurti vartotoja")
myg1.pack(side=LEFT)
myg2 = Button(virsus, text="Naikinti vartotoja")
myg2.pack(side=LEFT)
myg3 = Button(virsus, text="Keisti vartotojo grupe")
myg3.pack(side=BOTTOM)
root.mainloop()
def informacija():
root = Tk()
root.title("Vartotoju informacija")
root.geometry("400x100")
tekstas = Text(root, height=1, width=15)
tekstas.pack(side=TOP)
virsus = Frame(root)
virsus.pack()
apacia = Frame(root)
apacia.pack(side=BOTTOM)
myg1 = Button(virsus, text="Rodyti informacija", command=lambda: gauti())
myg1.pack(side=BOTTOM)
def gauti():
imti = tekstas.get("1.0", "end-1c")
info = subprocess.call("id '{imti}' ".format(imti=imti), shell=True)
w = Label(root, text= "info")
w.pack(LEFT)
root.mainloop()
myg1 = Button(virsus, text="Filtruoti pagal uzklausa", command=filtras)
myg2 = Button(apacia, text="Filtrouti pagal vartotoju prisijungimus", command=vartotojas)
myg3 = Button(virsus, text="Atidaryti/uzdaryti portus", command=portas)
myg4 = Button(apacia, text="Administruoti vartotojus", command=administ)
myg5 = Button(apacia, text="Vartotojo informacija", command=informacija)
myg1.pack(side=LEFT)
myg2.pack(side=RIGHT)
myg3.pack(side=LEFT)
myg4.pack(side=RIGHT)
myg5.pack(side=RIGHT)
root.mainloop()
答案 0 :(得分:1)
对于我所看到的,语句w.pack(LEFT)
只需要一个关键字(即w.pack(side=LEFT)
。没有关键字,它需要另一种参数(当调用help(Button.pack)
时,你会看到这个位置参数将是一个字典)