2

Can someone look at my code below and please tell me what I'm doing wrong. I've searched online for hours about this and I just can't see what I'm incorrectly doing.

from tkinter import *

#Function
def total():
    result = "1000"
    if ACvalue.get() == "AC" and Adultvalue.get() == "Adult" and NACvalue.get() == "N/AC":
        data.insert(0,result)

#Window
window = Tk()
window.title("Train Ticket Reservation")


ACvalue = StringVar()
NACvalue = StringVar()
Adultvalue = StringVar()
childvalue = StringVar()
data = StringVar()

#Creating Label 1
l1 = Label(window, text = "Coach: ")
l1.grid(column=0, row= 0)
#Creating Radio button 1
r1 = Radiobutton(window, text = "AC", value = "AC", variable=ACvalue)
r1.grid(column = 1, row = 0)
#Creating Radio button 2
r2 = Radiobutton(window, text = "N/AC", value = "N/AC", variable=NACvalue)
r2.grid(column = 2, row = 0)

#Creating Label 2
l2 = Label(window, text = "Person Type")
l2.grid(column = 0, row = 1)
#Creating Check Button 1
c1 = Checkbutton(window, text = "Adult",variable = Adultvalue)
c1.grid(column = 1, row = 1)
#Creating Check Button 2
c2 = Checkbutton(window, text = "Child", variable=childvalue)
c2.grid(column = 2, row = 1)

#Creating Entry
e1 = Entry(window, textvariable = data)
e1.grid(column = 1, row = 2)

#Creating Button
b1 = Button(window, text = "TOTAL", command = total())
b1.grid(columnspan = 1, row = 2)
#Loop
window.mainloop()

i dont know what else can i do to get the total total value on entrybox

Lion14706
  • 77
  • 4
  • Does this help? http://stackoverflow.com/q/5767228/7432 – Bryan Oakley Jul 26 '22 at 21:08
  • Does this answer your question? [Why is the command bound to a Button or event executed when declared?](https://stackoverflow.com/questions/5767228/why-is-the-command-bound-to-a-button-or-event-executed-when-declared) – Delrius Euphoria Jul 26 '22 at 21:50
  • 1
    Since you didn't respond to the above two comments: Exclude the parentheses after `command = total()` in the button declaration. – OmegaO333 Jul 27 '22 at 19:54

0 Answers0