ALLBLOG ABOUT CODING AND CODE: January 2021

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

-

Monday, 4 January 2021

Python tkinter basic

What is Tkinter ?     Tkinter is a library that is pre-installed in python used to make GUI like Calculator,
Login system, Notepad etc. open python idle or pycharm as python ide

and make a new file name main.py,  Start typing

from tkinter import*   -  "this import all tools from tkinter

 root = Tk()      - "root is the name Tk "  *note always the first letter of Tk is capital

root.mainloop() - "type the name of tk+.mainloop(),  mainloop() is used to run your application"

Setting the geometry or size of tkinter window -
 TYPE
 root.geometry("1000x500+0+0")  -  ("width" x "length" + "x position" + "y position")
Changing title of tkinter window -
 TYPE 
root.title("tkinter") - 
("type your title here")
Using minsize and maxsize 

root.minisize(200,200) - ("width" ,
 "length") -
 this will set
 the minimum size of window, window
 size dose not get smaller than this
 size

root.maxsize(1300,600) -
 ("width" , "length") -
 this will set the maximum size of 
window, window size dose not get 
larger than this size
Making button 

Button name like
btn=Button(root,text="click") - Button this 
is thinter function that define we are making a button (where you want to place,text is used to put text on button)

and to see button in tkinter window we will to pack button there are two method to pack
1. button name.pack() - btn.pack()

2. btn=Button(root,text="click").pack()

  to be continued...(about tools)

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