'AttributeError: 'str' object has no attribute '_root' in python3 on windows 10

My code:

from tkinter import *
from tkinter.ttk import Combobox
import random

screen = Tk()
screen.title("Password Generator")
screen.geometry('600x400')
screen.configure(background ="gray")

def Password_Gen():
    global sc1
    sc1.set("")
    passw=""
    length=int(c1.get())
    lowercase='abcdefghijklmnopqrstuvwxyz'
    uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'+lowercase
    mixs='0123456789'+lowercase+uppercase+'@#$%&*'

    if c2.get()=='Low Strength':
        for i in range(0,length):
            passw=passw+random.choice(lowercase)
        sc1.set(passw)
    elif c2.get()=='Medium Strength':
            for i in range(0,length):
                passw=passw+random.choice(uppercase)
            sc1.set(passw)
    elif c2.get()=='High Strength':
            for i in range(0,length):
                passw=passw+random.choice(mixs)
            sc1.set(passw)

sc1=StringVar('')
t1=Label(screen,text='Password Generator',font=('Arial',25),fg='green',background ="gray")
t1.place(x=60,y=0)
t2=Label(screen,text='Password:',font=('Arial',14),background ="gray")
t2.place(x=145,y=90)

il=Entry(screen,font=('Arial',14),textvariable=sc1)
il.place(x=270,y=90)
t3=Label(screen,text='Length: ',font=('Arial',14),background ="gray")
t3.place(x=145,y=120)

t4=Label(screen,text='Strength:',font=('Arial',14),background ="gray")
t4.place(x=145,y=155)

c1=Entry(screen,font=('Arial',14),width=10)
c1.place(x=230,y=120)

c2=Combobox(screen,font=('Arial',14),width=15)
c2['values']=('Low Strength','Medium Strength','High Strength')
c2.current(1)
c2.place(x=237,y=155)

b=Button(screen,text='Generate!',font=('Arial',14),fg='green',background ="gray",command=gen)
b.place(x=230,y=195)

screen.mainloop()

For some reason I'm keep getting those errors:

Traceback (most recent call last):
  File "C:\Users\z\3D Objects\birthday\passwordgeneratorgui.py", line 32, in <module>
    sc1=StringVar('')
  File "C:\Users\z\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 540, in __init__
    Variable.__init__(self, master, value, name)
  File "C:\Users\z\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 372, in __init__
    self._root = master._root()
AttributeError: 'str' object has no attribute '_root'

How can I fix those errors?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source