'im trying to gather inputs in tkinter but it only works through my main source of code and not classes for GUI
so i'm trying to create a GUI where I can take in inputs for both new and existing users to then put them into a database the problem is when its in a class it doesnt work and for my main code both would be in classes so i can call them forward when needed i think it a problem initializing them and i dont know how to sort it
from tkinter import ttk
from tkinter import *
def btnClickFunctio():
print('log in enter clicked')
inp = userinput.get(1.0, "end")
print(inp)
inpu= passinput.get(1.0, "end")
print(inpu)
inputs= coninput.get(1.0, "end")
print(inputs)
def blogin():
print('log in clicked')
inuser = luserinput.get(1.0, "end")
print(inuser)
inpass= lpassinput.get(1.0, "end")
print(inpass)
def login():
Label(root, text=' ', bg='#008B8B', font=('arial', 1000, 'normal')).place(x=000, y=000)
Label(root, text='username', bg='#008B8B',fg='white', font=('arial', 16, 'normal')).place(x=555, y=150)#labels
Label(root, text='password', bg='#008B8B',fg='white', font=('arial', 16, 'normal')).place(x=555, y=212)
luserinput=tk.Text(root,height = 1,width = 20,font=('arial', 16, 'normal'))
luserinput.pack()#text input boxs
luserinput.place(x=485, y=175)
lpassinput=tk.Text(root,height = 1,width = 20,font=('arial', 16, 'normal'))
lpassinput.pack()
lpassinput.place(x=485, y=237)
Button(root, text='Enter', bg='white', font=('arial', 16, 'normal'), command=blogin).place(x=573, y=380)#button
root = Tk()
root.geometry('1200x700')
root.configure(background='#008B8B')
root.title('sign up')
Button(root, text='Enter', bg='white', font=('arial', 16, 'normal'), command=btnClickFunctio).place(x=573, y=380)#button
Label(root, text='username', bg='#008B8B',fg='white', font=('arial', 16, 'normal')).place(x=555, y=150)#labels
Label(root, text='password', bg='#008B8B',fg='white', font=('arial', 16, 'normal')).place(x=555, y=212)
Label(root, text='confirm password', bg='#008B8B',fg='white', font=('arial', 16, 'normal')).place(x=524, y=270)
userinput=tk.Text(root,height = 1,width = 20,font=('arial', 16, 'normal'))
userinput.pack()#text input boxs
userinput.place(x=485, y=175)
passinput=tk.Text(root,height = 1,width = 20,font=('arial', 16, 'normal'))
passinput.pack()
passinput.place(x=485, y=237)
coninput=tk.Text(root,height = 1,width = 20,font=('arial', 16, 'normal'))
coninput.pack()
coninput.place(x=485, y=300)
Button(root, text='log in', bg='#BF3EFF', font=('arial', 16, 'normal'), command=login).place(x=20, y=50)
root.mainloop()
I would like to find a way to do these both within classes but i shorted and separated the code and thats how i found out theres only one way working so far the error is the same for each class on my main code:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\jodie\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\jodie\OneDrive\Desktop\home\python\inputs.py", line 15, in blogin
inuser = luserinput.get(1.0, "end")
NameError: name 'luserinput' is not defined
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
