gpt4 book ai didi

python - 按下按钮后 Tkinter.Label 不显示

转载 作者:太空宇宙 更新时间:2023-11-04 05:10:14 24 4
gpt4 key购买 nike

我正在努力做到,在我按下按钮后,我会在标签中显示获取的信息,但是,我似乎无法让标 checkout 现在 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()

最佳答案

就我所见,声明 w.pack(LEFT) 只需要一个关键字(即 w.pack(side=LEFT)。没有关键字,它期望另一种参数(当调用 help(Button.pack) 时,您会看到这个位置参数将是一个字典)

关于python - 按下按钮后 Tkinter.Label 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43170244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com