@@ -16,30 +16,44 @@ def select_or_create_user():
1616
1717 # Create custom dark-themed dialog
1818 dialog = tk .Toplevel ()
19- dialog .title ("Select or Create User" )
19+ dialog .title ("User Login " )
2020 dialog .configure (bg = "#161921" )
2121 dialog .resizable (False , False )
2222
23- # Prompt text
24- if existing_users :
25- prompt = f"Existing users: { ', ' . join ( existing_users ) } "
26- else :
27- prompt = "No users found. Please enter a new username:"
23+ # --- Center dialog on screen ---
24+ dialog . update_idletasks ()
25+ x = ( dialog . winfo_screenwidth () - dialog . winfo_reqwidth ()) // 2
26+ y = ( dialog . winfo_screenheight () - dialog . winfo_reqheight ()) // 2
27+ dialog . geometry ( f"+ { x } + { y } " )
2828
29- prompt_label = tk .Label (dialog , text = prompt , fg = "white" , bg = "#161921" , font = ("Segoe UI" , 10 , "bold" ))
30- prompt_label .pack (pady = (15 , 5 ), padx = 20 )
29+ # Prompt label
30+ prompt_label = tk .Label (dialog , text = "Enter username:" ,
31+ fg = "white" , bg = "#161921" ,
32+ font = ("Segoe UI" , 10 , "bold" ))
33+ prompt_label .pack (pady = (15 , 5 ))
3134
3235 # Entry field
33- username_entry = tk .Entry (dialog , font = ("Segoe UI" , 10 ), bg = "#202329" , fg = "white" , insertbackground = "white" , width = 30 , relief = tk .SOLID , highlightbackground = "white" , highlightthickness = 3 )
36+ username_entry = tk .Entry (dialog , font = ("Segoe UI" , 10 ),
37+ bg = "#202329" , fg = "white" , insertbackground = "white" ,
38+ width = 30 , relief = tk .SOLID ,
39+ highlightbackground = "white" , highlightthickness = 3 ,
40+ justify = "center" )
3441 username_entry .pack (pady = 5 , padx = 20 , ipady = 4 )
3542
43+
3644 result = {"username" : None }
3745
38- # Button functions
46+
3947 def on_ok ():
40- result ["username" ] = username_entry .get ().strip ()
48+ username = username_entry .get ().strip ()
49+ if not username : # empty input
50+ messagebox .showerror ("Invalid Username" , "Username cannot be empty." )
51+ return
52+ result ["username" ] = username
53+ root .quit ()
4154 dialog .destroy ()
4255
56+
4357 def on_cancel ():
4458 dialog .destroy ()
4559 root .destroy ()
@@ -60,10 +74,6 @@ def on_cancel():
6074
6175 username = result ["username" ]
6276
63- if not username :
64- messagebox .showerror ("No Username" , "Username is required to continue." )
65- exit ()
66-
6777 # Create user folders/files if needed
6878 user_path = os .path .join (USERS_DIR , username )
6979 os .makedirs (user_path , exist_ok = True )
0 commit comments