0
# Definitions
def Clear():
    user.set('')
    passw.set('')
    cuser.set('')
    cpassw.set('')

def Register():
    register = Tk()
    register.geometry('700x500')
    register.title('Your Pass')
    register['bg'] = 'Black'
    register.wm_iconbitmap(r'C:\Users\ethan\Dropbox\My PC (DESKTOP-6TT1M3A)\Desktop\Projects\Your Pass\YourPass.ico')

    # Create Variables
    cuser = StringVar() # Create Username Variable
    cpassw = StringVar() # Create Password Variable

    # Create Account Function
    def Create():
        cuser.set('')
        cpassw.set('')

    # Register Page Contents
    cuserEntry = Entry(register, textvariable = cuser).pack(padx = 5, pady = 10)
    cpasswEntry = Entry(register, textvariable = cpassw, show='*').pack(padx = 5, pady = 10)

    Create = Button(register, text='Create', command = Create).pack(padx = 0, pady=10)
    Close = Button(register, text='Close', command = Create).pack(padx = 0, pady=10)

I have tried multiple solutions and none of them seem to work. It is supposed to be a password system and I want to make sure all of the buttons and such are in place before I start with the SQL. So if you could tell me what to change, please do let me know.

brrrrrrrt
  • 51
  • 2
  • 13
  • Do you get an error? If so, what is the error. Usually it tells you what's wrong. – Bryan Oakley Mar 19 '21 at 23:29
  • Also your `cuserEntry` and `cpasswEntry` variable are always going to be `None`. For more info check [this](https://stackoverflow.com/a/66385069/11106801) – TheLizzard Mar 19 '21 at 23:31

2 Answers2

0

Because you assign a vallue to them, cuser and cpassw are local to the Register function. You need

    global cuser, cpassw

at the beginning of the function.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
0

I think you should avoid using globals, which have a long been considered bad. Instead you can use a class as illustrated below.

import tkinter as tk

class Register:
    def __init__(self):
        window = self.window = tk.Tk()
        window.geometry('700x500')
        window.title('Your Pass')
        window['bg'] = 'Black'
        window.wm_iconbitmap(r'C:\Users\ethan\Dropbox\My PC (DESKTOP-6TT1M3A)\Desktop\Projects\Your Pass\YourPass.ico')

        self.cuser = tk.StringVar()
        self.cpassw = tk.StringVar()

        self.cuserEntry = tk.Entry(window, textvariable=self.cuser)
        self.cuserEntry.pack(padx=5, pady=10)
        self.cpasswEntry = tk.Entry(window, textvariable=self.cpassw, show='*')
        self.cpasswEntry.pack(padx=5, pady=10)

        tk.Button(window, text='Create', command=self.create).pack(padx=0, pady=10)
        tk.Button(window, text='Close', command=self.close).pack(padx=0, pady=10)

        window.mainloop()

    def create(self):
        self.cuser.set('')
        self.cpassw.set('')

    def clear(self):
        self.cuser.set('')
        self.cpassw.set('')

    def close(self):
        self.window.quit()


Register()
martineau
  • 119,623
  • 25
  • 170
  • 301