ALLBLOG ABOUT CODING AND CODE: December 2022

Sunday, 18 December 2022

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

guys this is my youtube channel link 
click here
and here you will get all code on google 
drive 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 from
entry 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 we
name 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 from
v1 entry is same to open it show you write good in v2
entry
else:
vv2.set("wrong, we are not happy") *
if the data from
v1 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 this

from 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 bots
a , b , c , d

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")


msg.askretrycancel("error","you click the button")  -  ("title","message you want to show")

Using check button in tkinter window
 TYPE

btn=Checkbutton(root,text="click").pack() - btn is name Checkbutton is function (where you want to place, text) .pack to see result
Using frame in tkinter window
 TYPE 

f1=Frame(root).pack() - f1 is name frame is function (where you wnt to place) .pack() to pack with tkinter window


Using label in tkinter window
 TYPE

la=Label(f1,text="first frame").pack() - la is name of label (where you want to place I place it in f1 frame ,text)
note first letter of Label is capital

Using image on button in tkinter window note you can add only png file in this method
and the image you want to add is always in your that folder where your main.py file 
 TYPE

type this -

mango = PhotoImage(file="hu.png") - mango is name of it like a variable PhotoImage is function(file="your full file name")

 make a button -

btn=Button(root,image=mango).pack() - Button is function (where you want to place,image=your image variable) 
Using radio button in tkinter window
 TYPE

var = IntVar() - first make a int variable

R1=Radiobutton(root, text="Option 1", variable=var, value=1).pack()  -  R1 in name Radiobutton is function 
(where you want to place,text="you want" ,variable="your int ariable name",value=1)

R2=Radiobutton(root, text="Option 2", variable=var, value=2).pack() - R2 in name Radiobutton is function 
(where you want to place,text="you want" ,variable="your int ariable name",value=2)
note* -  always value is 1 then 2  then 3 etc.
if you set same value it select all radio button

to be continued...(adding jpeg images, reading data from button, full use of .pack() etc )

Friday, 16 December 2022

Best ways to learn coding

Free ways You can search for it on YouTube but i recommend you CodeWithHarry CodeWithHarry is a youtube channel which prove add coding video free of cost he teaches C++ , python , C , C sharp , php , html , css , java , javascript, Android app development, java , kotlin etc He has a website also here is the link https://www.codewithharry.com Paid ways you can purchase the codes on udemy etc

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...