I am pretty new to Python and I would like some tips and criticism on my formatting style/code and what can be better organized. I am a bit shaky on how classes work, but I think that it can be used here to make it more simple.
from tkinter import *
from tkinter import ttk
import random
#frame setup
main = Tk()
frame = ttk.Frame(main)
button_frame = ttk.Frame(frame)
text_frame = ttk.Frame(frame)
text = Text((text_frame), borderwidth=10, height=8, width=20, relief="sunken",)
def complex_password(): #complex password function
password2 = []
password2.append(random.choice((capital)))
count = 0
x = ""
while count != 12:
roll = random.randint(1,4)
if roll == 1 or roll == 2:
password2.append(random.choice((letters)))
count +=1
if roll == 3 or roll == 4:
number = random.randint(0,9)
number = str(number)
password2.append(number)
count +=1
if count == 12:
password2 = x.join(password2)
text.insert(INSERT, password2)
text.insert(INSERT, "\n")
def simple_password(): #simple password function
y = ""
password1 = []
password1.append(random.choice((words)))
password1.append(random.choice((words)))
number = random.randint(1,99)
num = str(number)
password1.append(num)
password1 = y.join(password1)
text.insert(INSERT, password1)
text.insert(INSERT, "\n")
def clear_text(): #clear txt box function
text.delete(1.0, END)
#buttons
simple = ttk.Button(button_frame, text="Simple", command=simple_password)
complex = ttk.Button(button_frame, text="Complex", command=complex_password)
clear = ttk.Button(button_frame, text="Clear", command=clear_text)
#buttons grids
simple.grid(column=2, row=1)
complex.grid(column=1, row=1)
clear.grid(column=3, row=1)
text.grid()
#frame grids
frame.grid(column=1, row=2)
text_frame.grid(column=1, row=2)
button_frame.grid(column=1, row=1)
#misc settings
for child in frame.winfo_children(): child.grid_configure(padx=5, pady=10)
main.title("Password Gen")
main.resizable(width=FALSE, height=FALSE)
main.geometry("238x230")
words = ['Dog', 'Cat', 'Mouse', 'Fire', 'Ice', 'Basket', 'Tree', 'Tiger',
'Lion', 'Flash','Super', 'Light', 'Zoom','Speed', 'Pants', 'Shirt',
'Hat', 'Suit', 'Berry', 'Yogurt', 'Epic', 'Keyboard', 'Toe', 'Car',
'Truck', 'Bike', 'Motor', 'Hammer', 'Pizza', 'Heart', 'Arm','Joint',
'Saw', 'New', 'Carrots', 'Baby', 'Kiss', 'Backspace', 'Enter', 'Alt',
'Print', "Down", 'Up', 'Question', 'Rain', 'Forest','Red', 'Orange',
'Yellow', 'Green', 'Blue', 'Purple', 'Brown', 'Black', 'Indigo', 'Grey',
'Shadow', 'Eye', 'Brick', 'Twig', 'Gangster', 'Thug', 'Chains', 'Gold',
'Silver', 'Bronze', 'Platinum', 'Titanium', 'Exploding', 'Ladybug', 'Grass',
'Monkey', 'Rhino', 'Comma', 'Hair', 'Shark', 'Fish']
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n','o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
capital = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N','O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
main.mainloop() #end of GUI