Now we are learning about .get func ,.set() and entry funcreading/writing files wit python
Entry to take input from user
To use it typeguys this is my youtube channel linkclick hereand here you will get all code on googledrive click here
from tkinter import *
from tkinter import messagebox as msg
root=Tk()
root.title("Dream")
root.geometry("1500x700+0+0")
v1=Entry(root).pack() this is entry widget
.get function use to get data of entry
def got():
msg.showinfo("you type",f"you type {vv.get()}") #it get data fromentry field and show in messagebox
vv=StringVar() *this is variable
v1=Entry(root,textvariable=vv).pack()
v2=Button(root,text="show",command=got).pack() *this is button and wename it show and add a command to it
.set function use to set data in entry field
def got():
if vv.get()== "open":
vv2.set("you write good") *if the data fromelse:v1 entry is same to open it show you write good in v2
entry
vv2.set("wrong, we are not happy") *if the data fromv1 entry is not same to open it show wrong, we are not happy in v2
entry
learn about get in radio and check button, reading and writing a file use .get() func. with check box write like this from tkinter import * from tkinter import messagebox as msg root = Tk() def got(): if vv4.get() == 1: msg.showinfo("success","you oder is taken") else: msg.showinfo("thanks","thanks for using our servise") vv4 = IntVar() root.title("Dream") root.geometry("1500x700+0+0") v4 = Checkbutton(root, text="order food",variable=vv4, onvalue=1, offvalue=0,height=2, width=10).pack() # onvalue=1 mean when checkbox is check the value is 1 else 0 .
. we use variable to define var in check box v3 = Button(root, text="show", command=got).pack() root.mainloop()
use .get() func. with radio box write like thisfrom tkinter import * from tkinter import messagebox as msg root = Tk() def got(): if vv4.get() == 1: msg.showinfo("thanks","you are a male") elif vv4.get() == 2: msg.showinfo("thanks","you are a female") else: msg.showerror("error", "select gender") vv4 = IntVar() root.title("Dream") root.geometry("1500x700+0+0") Label(root,text="select gender").pack() v4 = Radiobutton(root,text="male",variable=vv4,value=1).pack() *value must be different v5 = Radiobutton(root,text="female",variable=vv4,value=2).pack() v3 = Button(root, text="show", command=got).pack() root.mainloop()
use of try and except try: #when try get error it run except except #error name: what you want to run when error comes to read line in python write like this f = open('pac.txt') #the name of file with full extension # read first line data = f.readline() print(data) # Read second line data = f.readline() print(data) # Read third line data = f.readline() print(data) # Read fourth line. and so on.. data = f.readline() print(data) f.close() #output my youtube channel is code with rehaan handling error while reading file def readFile(filename): try: #try will all ways exicute with open(filename, "r") as f: print(f.read()) except FileNotFoundError: # except exicute when it get an error like"FileNotFoundError","ValueError" etc print(f"File {filename} is not found") readFile("1.txt") readFile("2.txt") readFile("3.txt") # output is thanks File 2.txt is not found write into a file filename = "sample.txt" #name of file with open(filename, "w") as f: f.write("here the content come whis you want to write") like nam=input("write file name with extwnsion .txt: ") # first it will take name of file like I type code.txt filename=nam with open(filename, "w") as f: var=input("write message : ") # Then it will take msg witch you want to store in that file f.writelines(var) ####### this will I discuss on my youtube channel ######### to be continue(making a login system, etc)
Call botsa , b , c , d
Sunday, 18 December 2022
Use of Entry , .get() , .set(), reading and writing data , entry in python
Basic Styling in Tkinter
today topic is styling in tkinter
Whole thing in a video
styling is a basic and important roll in tkinter
first make a label or button
i will make a label name m
m=Label(root,text="hi",background="green").place(x=66,y=44) -
background="colour you want" this wil clange label background colour to green
you can use bg as background
m=Label(root,text="hi",foreground="green").place(x=66,y=44) -
foreground="colour you want" this wil clange label foreground colour to green
you can use fg as foreground
m=Label(root,text="hi",bg="green",borderwidth="59",font="helvetica 40 bold").place(x=66,y=44) -
font is property controler of label, button etc like font ="style,size,bold or not or bold italic "
other types of font style like
Times,Timesnewroman etc
use of relief
m=Label(root,text="hi",bg="green",borderwidth="59",relief=RAISED).place(x=66,y=44) -
relief="your style"
note* always relief style name capital like SUNKEN this is correct , SUNken THIs is wrong
In last I explain about full use of .pack() , .grid() , .place() extension
like in grid we can use pady, padx ,ipady ,ipadx this are literally use in styling like
i will make a awesome button
m=Button(root,text="hi",bg="green",borderwidth="10",relief=GROOVE,font="Times 15 bold italic").pack(pady=20,ipady=4,ipadx=20)
now we use some types of relief in this button
m=Button(root,text="hi",bg="green",borderwidth="10",relief=FLAT,font="Times 15 bold italic").pack(pady=20,ipady=4,ipadx=20)
m=Button(root,text="hi",bg="green",borderwidth="10",relief=SUNKEN,font="Times 15 bold italic").pack(pady=20,ipady=4,ipadx=20)
m=Button(root,text="hi",bg="green",borderwidth="10",relief=RAISED,font="Times 15 bold italic").pack(pady=20,ipady=4,ipadx=20)
m=Button(root,text="hi",bg="green",borderwidth="10",relief=RIDGE,font="Times 15 bold italic").pack(pady=20,ipady=4,ipadx=20)
to be continue....(reading data from buttons)
python tkinter basic tools
Tkinter tools - there are many tools in tkinter like messagebox,check button,radio button,frame,label,adding image to button with imagetk etc.
and we learn adding command with a button
Using messagebox in tkinter window
TYPE
note first of all we will import a package name massagebox
How to import - Type at upper like this -
from tkinter import messagebox as msg - as msg now we can use messagebox as msg like
type at lower-
note there are many messagebox function like- msg.showinfo(),msg.showwarning(),
showerror(), askokcancel(), askyesno(), askyesnocancel(),
askquestion() and askretrycancel() now see use of all and how it looks
msg.showinfo("error","you click the button") - ("title","message you want to show")
msg.showwarning("error","you click the button") - ("title","message you want to show")
msg.showerror("error","you click the button") - ("title","message you want to show")
msg.askokcancel("error","you click the button") - ("title","message you want to show")
msg.askyesno("error","you click the button") - ("title","message you want to show")
msg.askyesnocancel("error","you click the button") - ("title","message you want to show")
msg.askquestion("error","you click the button") - ("title","message you want to show")
Friday, 16 December 2022
Best ways to learn coding
Use of Entry , .get() , .set(), reading and writing data , entry in python
Now we are learning about .get func ,.set() and entry func reading/writing files wit python Entry to take input from user To use it type guy...
-
What is Tkinter ? Tkinter is a library that is pre-installed in python used to make GUI like Calculator, Login system, Notepad etc. open...
-
This is tkinter basic tools part2. In this we learn about adding jpeg images, basic use of .pack() etc. Adding jpeg in button TYPE this...
-
Tkinter tools - there are many tools in tkinter like messagebox,check button,radio button,frame,label,adding image to button with imagetk e...