Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How To Let Your Main Window Appear after succesful login in Tkinter

from tkinter import * #Imports Tkinter
import sys #Imports sys, used to end the program later

root=Tk() #Declares root as the tkinter main window
top = Toplevel() #Creates the toplevel window

entry1 = Entry(top) #Username entry
entry2 = Entry(top) #Password entry
button1 = Button(top, text="Login", command=lambda:command1()) #Login button
button2 = Button(top, text="Cancel", command=lambda:command2()) #Cancel button
label1 = Label(root, text="This is your main window and you can input anything you want here")

def command1():
    if entry1.get() == "user" and entry2.get() == "password": #Checks whether username and password are correct
        root.deiconify() #Unhides the root window
        top.destroy() #Removes the toplevel window

def command2():
    top.destroy() #Removes the toplevel window
    root.destroy() #Removes the hidden root window
    sys.exit() #Ends the script


entry1.pack() #These pack the elements, this includes the items for the main window
entry2.pack()
button1.pack()
button2.pack()
label1.pack()

root.withdraw() #This hides the main window, it's still present it just can't be seen or interacted with
root.mainloop() #Starts the event loop for the main window
Comment

PREVIOUS NEXT
Code Example
Python :: how to close ursina screen 
Python :: how to make a random question generator in python 
Python :: Shuffle the data before GridSearchCV 
Python :: series floor 
Python :: sklearn grid search show progress 
Python :: matplotlib remove white lines between contour 
Python :: python power 
Python :: how to add items to tuple in python 
Python :: enumerate 
Python :: how to list gym envirolments 
Python :: snakeviz python profile 
Python :: python loop nest shorthand 
Python :: simulate gravity in pythpn 
Python :: python 3d list 
Python :: django get current user in form 
Python :: undef variable 
Python :: python split space or tab 
Python :: convert numpy array to tfrecord and back 
Python :: preprocessing data in python 
Python :: python generalised eigenvalue problem 
Python :: get the creating date of files ftp python 
Python :: python time.sleep 
Python :: NumPy fliplr Syntax 
Python :: django login required class based views 
Python :: python zip file 
Python :: stripping whitespace in python 
Python :: how to connect ip camera to opencv python 
Python :: Python program to count Even and Odd numbers using while loop in a List 
Python :: how to call a class from another class python? 
Python :: python menentukan genap ganjil 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =