ALLBLOG ABOUT CODING AND CODE: python tkinter basic tools part2

Thursday, 7 January 2021

python tkinter basic tools part2

 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 at upper

from PIL import Image,ImageTk  -  this import jpeg format allow


Type this in code-


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


mango = ImageTk.PhotoImage(photo) - mango is name of variable ImageTK.PhotoImage is function to allow jpeg(your photo image

 variable)


 make a button -

btn=Button(root,image=mango).pack() - Button is function (where you want to place,image=your ImageTK variable) 


Full use of .pack()


these is some of them -

 -anchor, -fill, -ipadx, -ipady, -padx, -pady, or -side etc


side will set side - like left,rigth,top,bottom


type for side left - 


la=Label(f1,text="first frame").pack(side=LEFT)


type for side right -


la=Label(f1,text="first frame").pack(side=RIGHT)


type for side top - 


la=Label(f1,text="first frame").pack(side=TOP)


type for side bottom - 


la=Label(f1,text="first frame").pack(side=BOTTOM)


use of pady - this set pading from x,y axis


btn=Button(root,image=photo).pack(pady=20)  - set padding from y axis (pady=set number)


button with payding 9


button with payding 20


use of padx


btn=Button(root,image=photo).pack(padx=20) - set padding from x axis (pady=set number)


use of fill - this fill from x or y and both axis


btn=Button(root,image=photo).pack(fill="x")


btn=Button(root,image=photo).pack(fill="y")


use of anchor - we can set label or anything to all direction


these are sides of anchor

 n, ne, e, se, s, sw, w, nw, or center


la=Label(f1,text="first frame").pack(anchor="w")


use of ipady - this set inner pading from y axis


btn=Button(root,image=photo).pack(ipady="40")


use of ipadx - this set inner pading from x axis


btn=Button(root,image=photo).pack(ipadx="40")




use of .grid()


we can use all this -anchor, -fill, -ipadx, -ipady, -padx, -pady, or -side tools in it 


use of row column in grid


la=Label(root,text="first frame").grid(row=5,column=4)   - la is name of label(where you want to place,text="you want").grid(row=row number,column=column number)

use of .place()


la=Label(f1,text="first frame").place(x=30,y=400)  - la is name of label(where you want to place,text="you want").place(x=your x position,y=your y position)


Adding command with button


make a button

btn=Button(root,text="press me",command=hi).grid()

when button click command

hi will execute

type upper from button line 


def hi(): - def is function hi() is function name : is end for function

    msg.showinfo("hi","smile")



to be continued...(Readind data,styling etc. )

-

1 comment:

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