Using Classes And Objects To Create GUIs | Python Tkinter GUI Tutorial In Hindi #25

preview_player
Показать описание


Best Hindi Videos For Learning Programming:

Follow Me On Social Media
Рекомендации по теме
Комментарии
Автор

Harry Bhaiya itna pyar kesy sambhalo gye ap.

Love you brother. You clear concepts in a straight way.

abdurrehmankhalid
Автор

from tkinter import *


class Calculation(Tk):
def __init__(self):
super().__init__()
self.geometry("800x600")

def Heading(self):
self.head = Label(text = "Calculate value", font = ("comic", 12 , "bold"))
self.head.grid(row = 0, column = 0)

def value_assigining(self):
self.val_a = IntVar()
self.val_b = IntVar()
self.label1 =Label(text = "Enter the first value")
self.label2 = Label(text="Enter the second value")
self.label1.grid(row = 1, column = 0)
self.label2.grid(row = 2 , column = 0)
self.val1 = Entry(textvariable = self.val_a)
self.val2 = Entry(textvariable = self.val_b)
self.val2.grid(row = 2, column = 1)
self.val1.grid(row = 1, column = 1)

def add(self):
self.a = self.val_a.get()
self.b = self.val_b.get()

self.c =self.a + self.b

self.val_c = IntVar()
self.val_c.set(self.c)
self.soluti =
self.soluti.grid(row=5, column=1)

def sub(self):
self.a = self.val_a.get()
self.b = self.val_b.get()

self.c = self.a - self.b

self.val_c = IntVar()
self.val_c.set(self.c)
self.soluti =
self.soluti.grid(row=5, column=1)

def mul(self):
self.a = self.val_a.get()
self.b = self.val_b.get()

self.c = self.a * self.b

self.val_C = IntVar()
self.val_c.set(self.c)
self.soluti =
self.soluti.grid(row=5, column=1)

def div(self):
self.a = self.val_a.get()
self.b = self.val_b.get()

self.c = self.a / self.b

self.val_c = IntVar()
self.val_c.set(self.c)
self.soluti = Label(textvariable = self.val_c)
self.soluti.grid(row = 5, column = 1)






def addition(self):
self.sol = Button(text = "+" , command = self.add )
self.sol.grid(row = 4, column =0)

def subtract(self):
self.solu = Button(text = "-", command = self.sub)
self.solu.grid(row = 4, column = 1)

def multiplication(self):
self.solu = Button(text="x", command=self.mul)
self.solu.grid(row=4, column=2)

def division(self):
self.solution = Button(text="÷", command=self.div)
self.solution.grid(row=4, column=3)

def only_label(self):
self.labe =Label(text = "Solution :")
self.labe.grid(row = 5, column = 0)




if __name__ == '__main__':
window= Calculation()
window.Heading()
window.value_assigining()
window.addition()
window.subtract()
window.multiplication()
window.division()
window.only_label()
window.mainloop()

technomusiccloud
Автор

from tkinter import *
def Login():
print("Login please wait")

class PANDEYID(Tk):
def __init__(self):
super().__init__()
self.geometry("766x455")
self.title("apna page")

def head(self):
Label(self, text="apna company", pady=7, font="comicsams 15 bold", bg="red").grid(row=0, column=4)

def name(self):
Label(self, text="Name", font="lucida 10 bold").grid(row=2, column=1)
self.var=StringVar()
Entry(self, textvariable=self.var, border=3).grid(row=2, column=2)

def password(self):
Label(self, text="Password", font="lucida 10 bold").grid(row=3, column=1)
self.pvar=StringVar()
Entry(self, textvariable=self.pvar, border=3, show="*").grid(row=3, column=2)
Button(self, text="Login", border=4, command=Login).grid(row=5, column=3)
if __name__=="__main__":
window=PANDEYID()
window.head()
window.name()
window.password()
window.mainloop()

mithileshpandey
Автор

# Functions:-
# 1. favicon(ico_filename)
# 2. menu(menu_names)
# 3. heading(text)
# 4. radiobuttons(radio_names)
# 5. button(text)
# 6. statusbar(text)

from tkinter import *

class GUI(Tk):
def __init__(self):
super().__init__()
self.geometry("900x600")

def favicon(self, filename):
self.wm_iconbitmap(filename)

def menu(self, *args):
menu = Menu(self)
for menu_name in args:

self.config(menu=menu)

def heading(self, text):
Label(self, text=text, bg="grey", fg="white", font="lucida 18 bold", pady=8).pack(side=TOP, fill=X)


def radiobuttons(self, *args):
var = StringVar()
var.set("r")
for radio in args:
Radiobutton(self, text=f"{radio}", variable=var, value=f"{radio}", font="lucida 9").pack()

def button(self, text):
Button(self, text=text, bg="grey", fg="white", pady=5, padx=5).pack()

def statusbar(self, text):
var = StringVar()
var.set(text)
Label(self, textvariable=var, relief=SUNKEN, pady=10, font="lucida 12", bg="grey", fg="white").pack(side=BOTTOM, fill=X)

akashgupta
Автор

class custom(Tk):
def __init__(self):
super().__init__()
self.geometry("977x898")
def addentries(self):
self.username=StringVar()
self.password=StringVar()
Label(self, text="Enter Name").grid(row=1, column=1)
Entry(self, textvariable=self.username).grid(row=1, column=2)
Label(self, text="Password").grid(row=2, column=1)
Entry(self, textvariable=self.password).grid(row=2, column=2)
def display(self):
tmsg.showinfo("Details", f"Your details are "+f"{self.username.get()} and {self.password.get()}")
def addbutton(self, text):
Button(self, text=text, command=self.display).grid(row=3, column=2)
if __name__=="__main__":
window=custom()# root now replaced ho chuka h window se
window.addentries()
window.addbutton("Get your entries")
window.mainloop()

ankuragarwal
Автор

beacuse now i beacame a master level python proframmmer as i know more than 14 modules and a developer i ma a expert level programmer i knew this before some days when i saw my level i got a master beacuse i made people lern also python from me only django and flask is left for my developing work i am a developer master llike harry bhai i develop games gui and web gui and web will be realeased also the games will be realeased i didnt ler ai beacuse i need harwares for that like rasberry pi and all thats why after me being 18 i will do that too but for now i am a master of developer an expert

parthacodes
Автор

Mai Phirse ek Window resizer Banaya hu oops se
from tkinter import *
class GUI(Tk):
def __init__(self):
super().__init__()
self.geometry("433x244")
def heading(self):
self.head=Label(self, text="Window Resizer", font="comicsansn 23 bold")
self.head.grid(row=0, column=1, padx=50)
def main(self):
self.width=Label(self, text="Width").grid(pady=20, padx=20)
self.height=Label(self, text="Height").grid(pady=20, padx=20)
def var(self):
self.widthvar=StringVar()
self.heightvar=StringVar()
self.widthentry=Entry(self, textvariable=self.widthvar)
self.heightentry=Entry(self, textvariable=self.heightvar)
self.widthentry.grid(row=1, column=1)
self.heightentry.grid(row=2, column=1)
def apply(self):

def button(self):
self.b1=Button(self, text="Apply", command=self.apply)
self.b1.grid(row=3, column=1)
if __name__ == '__main__':
window=GUI()
window.heading()
window.main()
window.var()
window.button()
window.mainloop()

PinkyShaw
Автор

Thanks for the video
Great as always
Challenge Accepted

vikaspal
Автор

Thanks sir, pls make more video based on class or oops concept 🙏🙏🙏👍

nikhilsharma
Автор

from tkinter import *

class calci(Tk):
def __init__(self):
super().__init__()
self.geometry("500x500")
self.title("Calci Ex")

def add(self, a, b):
print(a+b)

if __name__ == '__main__':
window = calci()
window.add(2, 8)
window.mainloop()

chetantaneja
Автор

Harry bhai bahut maza aata hai dekhne me or seekhne me, koi book recommend krdo agar ho toh!!

krdshow
Автор

from tkinter import *

class sayHello(Tk):
def __init__(self):
super().__init__()
self.geometry("200x200")
self.label=Label(text="Hello! everyone").pack()


if __name__ == '__main__':
window=sayHello()
window.mainloop()

divya
Автор

Challenge Accepted: below is my code

# Todo: Creating a simple GUI using OOPs concept where there will be a button: on clicking which will show your name on a display frame

from tkinter import *


class GUI(Tk):
def __init__(self): # here 'self' is the 'root' we used to define
super().__init__() # super() function used to access the parent class (class Tk) Constructor
self.geometry("700x300")
self.title("OOPs Concept in GUI building")
self.resizable(False, False)

def btn_frame(self):
self.btnframe = Frame(self, borderwidth = 2, bg = "red", relief = RAISED)
self.btnframe.pack(side = LEFT, fill = BOTH)
self.heading = Label(self.btnframe, text ="Press the button to reveal your name", font = ('Lucida', 18, 'bold'), bg ="red", fg ="yellow")
self.heading.pack()
self.nbtn = Button(self.btnframe, text ="Show Name", command = self.show_name)
self.nbtn.pack(pady = 50)

def disp_frame(self):
self.dispframe = Frame(self, borderwidth = 2, bg = "green", relief = SUNKEN)
self.dispframe.pack(side = LEFT, fill = BOTH, expand = True)
self.inst = Label(self.dispframe, text = "Showing name here:", font = ('Lucida calligraphy', 12, 'bold'), bg = "green", fg = "orange")
self.inst.pack()

def show_name(self):
self.name = Label(self.dispframe, text = "Name: Kaustab", font = ('Helvetica', 18, 'bold'), bg = "green", fg = "blue")
self.name.pack(pady = 50)

if __name__ == '__main__':
window = GUI() # Creation of object for class GUI
window.btn_frame()
window.disp_frame()
window.mainloop()
# Warning: Bad colour scheme

kaustab
Автор

Challenge accepted

from tkinter import *
class Person(Tk):
def __init__(self):
super().__init__()
self.geometry("560x326")

def click_here(self):
print("Tkinter is simple but when you using class then its very complecated" )

def createbutton(self, text):
self.var=Button(text=text, width=19, command=self.click_here)
self.var.pack()
if __name__=="__main__":
root=Person()
root.createbutton("press here")
root.mainloop()

TechnoBooster
Автор

# this class creates a gui with button that when pressed updates the button

from tkinter import *
class GUI(Tk):
def __init__(self):
super().__init__()
self.geometry("500x300")
self.title("GUI for Updating Button text")
Label(self, text="Type and click on Button", font="Helvetica 17 bold").pack()
inputting=StringVar()
self.e1=Entry(self, textvariable=input)
self.e1.pack(pady=10)

def create_button(self):
self.b1=Button(self, text="Change Me!", font="Helvetica 10 bold", relief=RIDGE, command=self.update_it)
self.b1.pack(pady=20)




def update_it(self):
self.b1.destroy()
if self.e1.get()=="":
self.b1=Button(self, text="Empty Button", relief=RIDGE, font="Helvetica 10 bold", command=self.update_it)
else:
self.b1=Button(self, text=self.e1.get(), font="Helvetica 10 bold", relief=RIDGE, command=self.update_it)
self.b1.pack(pady=20)
self.update()



window=GUI()
window.create_button()
window.mainloop()

anshdholakia
Автор

from tkinter import *

class GUI(Tk):
def __init__(self):
super().__init__()
self.geometry("1600x900")
self.minsize(1600, 900)
self.maxsize(1600, 900)

def statusbar(self):
self.var = StringVar()
self.var.set("Ready")
self.statusbar = Label(self, textvar=self.var, relief=SUNKEN, anchor="w")
self.statusbar.pack(side = BOTTOM, fill = X)

def menu(self):
self.main = Menu(self)
self.m1 = Menu(self.main, tearoff=0)
Text File")
File...")
Window")
self.m1.add_separator()
File...")
Folder...")
Workspace from File...")
Recent")
self.m1.add_separator()
Folder to Workspace...")
Workspace As...")
Workspace")
self.m1.add_separator()

As...")
All")
self.m1.add_separator()

self.m1.add_separator()
Save")

self.m1.add_separator()
File")
Editor")
Folder")
Window")
self.m1.add_separator()

self.m2 = Menu(self.main, tearoff=0)


self.m2.add_separator()



self.m2.add_separator()


self.m2.add_separator()
in Files")
in Files")
self.m2.add_separator()
Line Comment")
Block Comment")
Expand Abbreviation")
self.m3 = Menu(self.main, tearoff=0)
All")
Selection")
Selection")
self.m3.add_separator()
Line Up")
Line Down")
Line Up")
Line Down")
Selection")
self.m3.add_separator()
Cursor Above")
Cursor Below")
Cursor to Line Ends")
Next Occurence")
Previous Occurence")
All Occurences")
self.m3.add_separator()
to Ctrl + Click for Multi-Cursor")
Selection Mode")
self.m4 = Menu(self.main, tearoff=0)
Pallete...")
View...")
self.m4.add_separator()

Layout")
self.m4.add_separator()


Control")



self.m4.add_separator()


Console")

self.m4.add_separator()
Wrap")
self.config(menu= self.main)
self.main.add_cascade(label="File", menu = self.m1)
self.main.add_cascade(label="Edit", menu = self.m2)
self.main.add_cascade(label="Selection", menu = self.m3)
self.main.add_cascade(label="View", menu = self.m4)

if __name__ == "__main__":
window = GUI()
window.statusbar()
window.menu()
window.mainloop()

sahiliit
Автор

maine geometry wala funtion banaya bro
from tkinter import *

class GUI(Tk):
def __init__(self):
super().__init__()

def initialsize(self, w, h):
self.geometry(f"{w}x{h}")

if __name__ == "__main__":
gui = GUI()
gui.initialsize(200, 300)
gui.mainloop()

HawkingMerchant
Автор

Haary Sir loved you series sinse now I am watching all videos

rahuljain
Автор

from tkinter import *

class GUI(Tk):
def __init__(self):
super().__init__()
self.geometry("623x573")

def ClickMe(self, name):
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid()
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=1, column=1)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=2, column=2)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=3, column=3)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=4, column=4)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=5, column=5)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=6, column=6)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=7, column=7)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=8, column=8)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=9, column=9)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=10, column=10)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=11, column=11)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=12, column=12)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=13, column=13)
Button(self, text=name, fg="black", bg="red", padx=10, pady=10).grid(row=14, column=14)


if __name__ == '__main__':
Windows = GUI()
Windows.ClickMe("Tab")
Windows.mainloop()

kartikkulshreshtha
Автор

from tkinter import *
class GUI(Tk):
def __init__(self):
super().__init__()
self.geometry("500x500")
def textnames(self, text1, text2, text3):
Label(text=text1, font="lucida 15 bold").place(x=0, y=0)
Label(text=text2, font="lucida 15 bold").place(x=0, y=50)
Label(text=text3, font="lucida 15 bold").place(x=0, y=100)
def textEntry(self):
self.Namevalue=StringVar()
self.Idvalue=StringVar()
self.stdvalue=StringVar()
self.NameEntry=Entry(self, textvariable=self.Namevalue).place(x=100, y=10)
self.IdEntry=Entry(self, textvariable=self.Idvalue).place(x=100, y=60)
self.stdEntry=Entry(self, textvariable=self.stdvalue).place(x=100, y=110)
def data(self):
f=open("data1.txt", "a")



def subButton(self, inptxt):
Button(self, text=inptxt, command=self.data).place(x=0, y=150)
if __name__ == '__main__':
app=GUI()
app.textnames("Name:", "Id:", "std:")
app.textEntry()
app.subButton("Submit")
app.mainloop()

shubham