#๐Ÿ”’ Review my learning - Login Script

9 messages ยท Page 1 of 1 (latest)

umbral shuttle
#

Hey all,

Just wanted to get some feedback on my script that ive been working on, and to see if there is anywhere i need to improve.

import customtkinter as ctk

Custom Functions

class FuncsMixin:
def geometry_centre_window(self, width, height):
self.update_idletasks()
x = (self.winfo_screenwidth() - width) // 2
y = (self.winfo_screenheight() - height) // 2
self.geometry(f"{width}x{height}+{x}+{y}")

LOGIN WINDOW

class LoginWin(ctk.CTk, FuncsMixin):
def init(self):
super().init()
self.title("Ordo Login")
self.geometry_centre_window(300, 400)

    # Main frame
    frame = ctk.CTkFrame(self, fg_color="transparent")
    frame.pack(expand=True)

    # Widgets
    self.welcome_label  = ctk.CTkLabel(frame, text="Welcome", font=ctk.CTkFont("Arial", 30, "bold"))
    self.username_label = ctk.CTkLabel(frame, text="Username")
    self.username_entry = ctk.CTkEntry(frame)
    self.password_label = ctk.CTkLabel(frame, text="Password")
    self.password_entry = ctk.CTkEntry(frame, show="*")
    self.spacefiller_label = ctk.CTkLabel(frame, text="")
    self.login_button   = ctk.CTkButton(frame, text="Login", command=self.login, text_color="#48494B", hover_color="#363636")

    # Bind 'Enter' key anywhere in this window to login
    self.bind("<Return>", lambda e: self.login())

    # Layout (same grid positions as original)
    self.welcome_label.grid(row=0, column=1, pady=10, sticky="news")
    self.username_label.grid(row=1, column=1, pady=0)
    self.username_entry.grid(row=2, column=1, pady=0)
    self.password_label.grid(row=3, column=1, pady=0)
    self.password_entry.grid(row=4, column=1, pady=0)
    self.spacefiller_label.grid(row=5, column=1, pady=0)
    self.login_button.grid(row=6, column=1, pady=0)

# Login Command
def login(self):
    username = "Admin"
    password = "2106"

    if self.username_entry.get() == username and self.password_entry.get() == password:
        print("Success")
        self.open_client_win()
    else:
        print("Failed")
        self.spacefiller_label.configure(text="Login failed", text_color="red")

# Open Client
def open_client_win(self):
    self.withdraw()
    ClientWin()

CLIENT WINDOW

class ClientWin(ctk.CTkToplevel, FuncsMixin):
def init(self):
super().init()
self.title("Ordo")
self.geometry_centre_window(900, 400)
self.protocol("WM_DELETE_WINDOW", self.on_close) #Enables the 'X' close window to destroy root.

def on_close(self):
    # Close root win as well
    self.master.destroy()

Start App

if name == "main":
app = LoginWin()
app.mainloop()

iron thistleBOT
#

@umbral shuttle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hallow gale
#

!code

Please edit your post to format the code for readability.

iron thistleBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

hardy marsh
#

@umbral shuttle

umbral shuttle
iron thistleBOT
iron thistleBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.