from tkinter import * #BASICS DAAA #window=Tk() # Instantiate a window for displaying content #window.geometry("500x500") #For setting sizes of the window #window.title("Face Rec GUI") # For setting title name #icon= PhotoImage(file=" #gesnhin.png") #window.iconphoto(True,icon) # Icon of the GUI #window.config(background="green") #Background Colour Change can pass hex value also #window.mainloop() #For displaying the window #LABELS #window=Tk() #photo=PhotoImage(file="genshin.png") #label= Label(window,text="GUI FOR FACE RECOGNITION",font=("Times New Roman",35,'italic'),fg="Blue",bg="green",relief=RAISED,bd=15,padx=25,pady=25,image=photo,compound="bottom") #For Showing Label Content.. fg is text colour bg is background colour relief is border style bd is border width padx and pad y are for spaces between border and text #label.pack() #For setting the name of the label by default centred #label.place(x=0,y=0) #For keeping the label in certain coordinates #window.mainloop() #BUTTONS #def click(): # print("You clicked the button") #window=Tk() #photo=PhotoImage(file="image.png") #button=Button(window,text="CLICK ME",command=click,font=("Comic Sans",30),fg="RED",bg="BLACK",activeforeground="RED",activebackground="BLACK",image=photo,compound="bottom") #Command is thing that we want it to do activeforeground and activebackground are clicking colours compound is for not overlapping image with text #button.pack() #window.mainloop() #ENTRY WIDGET #def submit(): # username=entry.get() # print("hello"+username) # entry.config(state=DISABLED) #def delete(): # entry.delete(0,END) #def backspace(): # entry.delete(len(entry.get())-1,END) #window=Tk() #entry=Entry(window,font=("Arial",50),fg="BLACK",bg="RED",show="*") show is for showing what we want to show apart from the actual #entry.insert(0,"TYPE YOUR TEXT HERE") #FOR DEFAULT TEXT #entry.pack(side=LEFT) side argument used for placing the widget #submitbutton= Button(window,text="submit",command=submit) #submitbutton.pack(side=RIGHT) #deletebutton= Button(window,text="delete",command=delete) #deletebutton.pack(side=RIGHT) #backspacebutton= Button(window,text="Backspace",command=backspace) #backspacebutton.pack(side=RIGHT) #window.mainloop() #CHECK BOXES #def display(): # if(x.get()==1): # print("You agreed") # else: # print("You don't agree") #window=Tk() #x=IntVar() #image1=PhotoImage(file="Screenshot(13).png") #checkbutton=Checkbutton(window,text="I agree to something",variable=x,onvalue=1,offvalue=0,command=display,font=("Arial",20),fg="green",bg="red",activeforeground="Green",activebackground="red",padx=10,pady=15,image=image1,compound="left") #checkbutton.pack() #window.mainloop() #DISCRETE CHECK BOXES #food=["pizza","hamburger","hotdog"] #def order(): # if (x.get()==0): # print("You ordered pizza") # elif (x.get()==1): # print("You ordered hotdog") #else: # print("huh") #window=Tk() #pizzaimage= PhotoImage(file="genshin.png.") #burgerimage= PhotoImage(file="name.png") #hotdogimage= PhotoImage(file="image.png") #foodimages=[pizzaimage,burgerimage,hotdogimage] #x=IntVar() #for index in range(len(food)): # radiobutton=Radiobutton(window,text=food[index],variable=x,value=index,padx=25,pady=10,font=("Comic Sans",50),image=foodimages[index],compound="left",indicatoron=False,width=375,command=order)#indicatoron=eliminate circle indicators # radiobutton.pack() # radiobutton.pack(anchor=W) #window.mainloop() #TEMPERATURE SCALES #def submit(): # print("The temperature is:"+str(scale.get())+"degrees c") #window=Tk() #scale=Scale(window,from_=100,to=0,length=600,orient=VERTICAL,font=("Arial",20),tickinterval=10,showvalue=0,troughcolor="blue",fg="red",bg="green")#Orientation Tickinterval adds numeric indicators for value #scale.pack() #button=Button(window,text="submit",command=submit) #button.pack() #window.mainloop() #LISTBOXES #def submit(): #food=[] #for index in listbox.curselection(): # food.insert(index,listbox.get(index)) #print("You have ordered:") #for index in food: # print(index) #def add(): # listbox.insert(listbox.size(),entrybox.get()) # listbox.config(height=listbox.size()) #def delete(): # for index in reversed(listbox.curselection()): # listbox.delete(index) # listbox.config(height=listbox.size()) #window=Tk() #listbox=Listbox(window,bg="green",font=("Constantia",35),width=12,selectmode=MULTIPLE) #listbox.pack() #listbox.insert(1,"pizza") #listbox.insert(2,"burger") #listbox.insert(3,"soup") #listbox.insert(4,"salad") #listbox.insert(5,"jam") #entrybox= Entry(window) #entrybox.pack() #addbutton= Button(window,text="add",command=add) #addbutton.pack() #deletebutton= Button(window,text="delete",command=delete) #deletebutton.pack() #submitbutton= Button(window,text="submit",command=submit) #submitbutton.pack() #window.mainloop() #MESSAGEBOXES #from tkinter import messagebox #import message box library #def click(): # messagebox.showinfo(title="This is an info message box",message="You are a person") #messagebox.showwarning(title="Warning", message="You have a Virus!!!") #messagebox.showerror(title="Error",message="Something went wrong") # if messagebox.askokcancel(title="ASK OK CANCEL",message="Do you want to continue?"): # print("You continued") # else: # print("You stopped") # if messagebox.askretrycancel(title="RETRY OR CANCEL", message="Do you want to retry or cancel?"): # print("You retried") #else: # print("You stopped") # if messagebox.askyesno(title="ASK YES OR NO",message="DOU YOU LIKE CAKE?"): # print("I like cake too") #else: # print("Why dont u like it?") # answer=(messagebox.askquestion(title="ASK QUESTION",message="DO YOU LIKE PIE?")) #if answer=="yes": # print("I like it too") #else: # print("Why dont u like it") # answer=(messagebox.askyesnocancel(title="ask yes no cancel",message="do u like to code?",icon='error'))#ICON FOR SELECTING TYPE OF ICON CAN BE WARNING ERROR OR INFO #if answer==True: # print("ME TOO") #elif answer==False: # print("WTF") #else: # print("YOU DODGED THE QUESTION") #window=Tk() #button=Button(window,command=click,text="click me") #button.pack() #window.mainloop() #COLOURCHOOSER #from tkinter import colorchooser #Bcoz its submodule #def click(): # window.config(bg=colorchooser.askcolor()[1])#CHANGES BG COLOUR #window=Tk() #window.geometry("420x420") #button= Button(text="click me",command=click) #button.pack() #window.mainloop() #TEXT AREA #def submit(): # innerput=text.get("1.0",END) # print(innerput) #window=Tk() #button=Button(window,command=submit,text="submit") #button.pack() #text= Text(window,bg="light yellow",font=("Ink Free",20),height=8,width=20,padx=20,pady=20,fg="purple") #text.pack() #window.mainloop() #FILE DIALOG #from tkinter import filedialog #def openfile(): # filepath=filedialog.askopenfilename(initialdir="C:\Users\brarj\PycharmProjects",title="Open file")#filetypes=()) #Gives path in strings filetype for what type we want to search for # file=open(filepath,"r") # print(file.read()) #file.close() #window=Tk() #button=Button(text="open",command=openfile) #button.pack() #window.mainloop() #SAVE FILES # def savefile(): # file=filedialog.asksaveasfile(defaultextension='.txt',filetypes=[("Text File",'txt"'),("HTML FILE",".html"),("ALL FILES",".*")])#use initialdir for saving into folder u want # if file is None: #Exception Handling # return # filetext=str(text.get(1.0,END)) #also can use console window for input using filetext=input("Enter some text") should once save file then u can input # file.write(filetext) # file.close # from tkinter import filedialog # window=Tk() #button= Button(window,text="save",command=savefile) #button.pack() #text=Text(window) #text.pack() #window.mainloop() #MENUBAR #def openfile(): # print("FIle has been opened") #Can change the function to open files using file dialog or smth #def savefile(): # print("FIle has been saved") #def cut(): # print("You cut text") #def copy(): # print("You copied text") #def paste(): # print("You pasted text") #window=Tk() #menubar=Menu(window) #window.config(menu=menubar) #filemenu= Menu(menubar,tearoff=0,font=("MV Boli",15)) #menubar.add_cascade(label="File",menu=filemenu) #filemenu.add_command(label="Open",command=openfile) #filemenu.add_command(label="Save",command=savefile) #filemenu.add_separator() #filemenu.add_command(label="Exit",command=quit) #editmenu=Menu(menubar,tearoff=0,font=("MV Boli",15))#Tearoff for removing line at the top #menubar.add_cascade(label="Edit",menu=editmenu) #editmenu.add_command(label="Cut",command=cut) #editmenu.add_command(label="Copy",command=copy) #editmenu.add_command(label="Paste",command=paste) #window.mainloop() #NEW WINDOW #def createwindow(): # newwindow=Tk() # window.destroy()#close out of old window #window=Tk() #Button(window,text="Create New Window",command=createwindow).pack() #TABS #from tkinter import ttk #window=Tk() #notebook=ttk.Notebook(window)#Manages collection of windows #tab1=Frame(notebook) #tab2=Frame(notebook) #notebook.add(tab1,text="Tab 1") #notebook.add(tab2,text="Tab 2") #notebook.pack(expand=True,fill="both")#Exapnd will expand to any space not used fill will fill space #Label(tab1,text="Hello",width=50,height=25).pack() #Label(tab2,text="Bye",width=50,height=25).pack() #window.mainloop() #PROGRESS BARS """from tkinter.ttk import * import time def start(): tasks=10 x=0 while x",dosomething)#format is like ,function""" window=Tk() window.mainloop()