1

I am trying to create a program that allows a user to either increment a value or enter it themselves into an entry in a system that looks something like this: The Basic Gui And this is my code

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()

The problem I am having is that the self.delay.get() returns PY_VAR1 OR PY_VAR0

I am truly stuck on what to do here can anyone help me out?

Dan Howe
  • 9
  • 10

2 Answers2

-1

Okay I dont know what happened but I removed the submit button on the line below the entry and now it works.

Dan Howe
  • 9
  • 10
  • 1
    If you longer need an answer, please delete the question. – Bryan Oakley May 05 '20 at 13:37
  • 1
    @BryanOakley as the menu says when you press delete ```We do not recommend deleting questions with answers because doing so deprives future readers of this knowledge.```. So this question will not be deleted incase some other person needs this! – Dan Howe May 05 '20 at 13:54
  • At the time I wrote my comment there wasn't a useful answer. – Bryan Oakley May 05 '20 at 14:06
-1

The problem is you dont use lambda on this line

 Button(ACGui, text="Submit", command=self.delay.set(self.new_delay)).grid(row=2, column=5)

It automaticly execute self.delay.set when u run your program. Try

 Button(ACGui, text="Submit", command=lambda:self.delay.set(self.new_delay)).grid(row=2, column=5)
Albert H M
  • 257
  • 2
  • 15
  • This won't work. `self.new_delay` is a StringVar so the problem will be the same, it will just occur later. In other words, this will still set the delay to something like `PY_VAR1`. – Bryan Oakley May 05 '20 at 14:05
  • well i just realize there is another problem, based on this. He must have set variable as IntVar(). – Albert H M May 05 '20 at 14:18