SUPER RED PANDA
SUPER RED PANDA

Reputation: 15

tkinter, storing users entry to proceed through the program (beginner)

the entry box is not storing a value when entered, rather it just checks it against what is in their current (which is nothing cause it is a blank textbox) have tried to use the .get however that has not been working thus far.

import tkinter as tk 
import tkinter.messagebox as box

window = tk.Tk()
window.state('zoomed')
window.title('')

def show_frame(fram):
    fram.tkraise()

def dialog1():

    username=txt.get()

    if (username == '3199'):
        show_frame(frame1)
   
    else:
        box.showinfo('info','Invalid Login')


window.rowconfigure(0, weight=1)
window.columnconfigure(0, weight=1)

frame1 = tk.Frame(window)
frame2 = tk.Frame(window)
frame3 = tk.Frame(window)


for frame in (frame1, frame2, frame3):
    frame.grid(row=0,column=0,sticky='nsew')

tk.Label(frame1, text = "ID number" ,font=('Arial', 40 ), fg = 'blue', bg = '#F0EAD6').place(x=450, y=300)

textbox = tk.StringVar()
txt = tk.Entry(frame1)
txt.place(x= 665, y= 311,width=300,height=40)

a = tk.Button(frame1, text ='Continue',font=('Arial', 52 ),fg = 'blue',bg = '#F0EAD6', command = dialog1())
a.place(x=605,y=500,width=300,height = 70)

window.mainloop()


           

Upvotes: 0

Views: 37

Answers (2)

user15801675
user15801675

Reputation:

You need to provide a reference of the function instead of calling the function. Or else, the function would be executed and the value returned by the function would be set as a command, which currently, is None.

In short, the button won't work.

Change this:

a = tk.Button(frame1, text ='Continue',font=('Arial', 52 ),fg = 'blue',bg = '#F0EAD6', command = dialog1())
a.place(x=605,y=500,width=300,height = 70)

to this:

a = tk.Button(frame1, text ='Continue',font=('Arial', 52 ),fg = 'blue',bg = '#F0EAD6', command = dialog1)
a.place(x=605,y=500,width=300,height = 70)

Upvotes: 1

scotty3785
scotty3785

Reputation: 7006

You are evaluating dialog1 before the button is pressed

Change

a = tk.Button(frame1, text ='Continue',font=('Arial', 52 ),fg = 'blue',bg = '#F0EAD6', command = dialog1())

to

a = tk.Button(frame1, text ='Continue',font=('Arial', 52 ),fg = 'blue',bg = '#F0EAD6', command = dialog1)

At the moment your code is trying to pass the result of dialog1 to the command attribute of the button rather than the function callback.

Upvotes: 0

Related Questions