PYTHON (tkinter) 在条目中创建增量值
PYTHON (tkinter) Creating an incremental value in an entry
我正在尝试创建一个程序,允许用户增加一个值或自己将其输入系统中的条目,如下所示:
The Basic Gui
这是我的代码
from tkinter import *
ACGui = Tk()
class GUI:
def __init__(self, start, stop, delay, buttons):
new_delay = delay
self.start_button = start
self.stop_button = stop
self.delay = StringVar()
self.new_delay = StringVar()
self.delay.set(delay)
self.new_delay.set(new_delay)
self.buttons = buttons
def delay_increment(self, op, num):
print(self.delay.get())
print(op)
print(num)
def create_gui(self):
Label(ACGui, text="Auto Clicker").grid(row=0, column=0)
Button(ACGui, text="+1", command=lambda: self.delay_increment("add", 1)).grid(row=1, column=1)
Label(ACGui, text="Delay: ").grid(row=2, column=0)
Entry(ACGui, text=self.delay, textvariable=self.new_delay, justify="center").grid(row=2, column=1)
Button(ACGui, text="Submit", command=self.delay.set(self.new_delay)).grid(row=2, column=5)
Button(ACGui, text="-1", command=lambda: self.delay_increment("sub", 1)).grid(row=3, column=1)
ACGui.mainloop()
main = GUI(1, 1, 2, 1)
main.create_gui()
我遇到的问题是 self.delay.get()
returns PY_VAR1
或 PY_VAR0
我真的不知道该怎么办,有人能帮我吗?
好吧,我不知道发生了什么,但我删除了条目下方行中的提交按钮,现在可以使用了。
问题是你没有在这一行使用 lambda
Button(ACGui, text="Submit", command=self.delay.set(self.new_delay)).grid(row=2, column=5)
当你运行你的程序时,它会自动执行self.delay.set。
尝试
Button(ACGui, text="Submit", command=lambda:self.delay.set(self.new_delay)).grid(row=2, column=5)
我正在尝试创建一个程序,允许用户增加一个值或自己将其输入系统中的条目,如下所示: The Basic Gui 这是我的代码
from tkinter import *
ACGui = Tk()
class GUI:
def __init__(self, start, stop, delay, buttons):
new_delay = delay
self.start_button = start
self.stop_button = stop
self.delay = StringVar()
self.new_delay = StringVar()
self.delay.set(delay)
self.new_delay.set(new_delay)
self.buttons = buttons
def delay_increment(self, op, num):
print(self.delay.get())
print(op)
print(num)
def create_gui(self):
Label(ACGui, text="Auto Clicker").grid(row=0, column=0)
Button(ACGui, text="+1", command=lambda: self.delay_increment("add", 1)).grid(row=1, column=1)
Label(ACGui, text="Delay: ").grid(row=2, column=0)
Entry(ACGui, text=self.delay, textvariable=self.new_delay, justify="center").grid(row=2, column=1)
Button(ACGui, text="Submit", command=self.delay.set(self.new_delay)).grid(row=2, column=5)
Button(ACGui, text="-1", command=lambda: self.delay_increment("sub", 1)).grid(row=3, column=1)
ACGui.mainloop()
main = GUI(1, 1, 2, 1)
main.create_gui()
我遇到的问题是 self.delay.get()
returns PY_VAR1
或 PY_VAR0
我真的不知道该怎么办,有人能帮我吗?
好吧,我不知道发生了什么,但我删除了条目下方行中的提交按钮,现在可以使用了。
问题是你没有在这一行使用 lambda
Button(ACGui, text="Submit", command=self.delay.set(self.new_delay)).grid(row=2, column=5)
当你运行你的程序时,它会自动执行self.delay.set。 尝试
Button(ACGui, text="Submit", command=lambda:self.delay.set(self.new_delay)).grid(row=2, column=5)