Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Master Code forms all control tkinter connect csv_insert_image.py

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Master Code forms all control tkinter connect csv_insert_image.py

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

import tkinter as tk

from tkinter import *


from tkinter import PhotoImage
from PIL import Image, ImageTk
from tkinter import filedialog

base = Tk() #Creating the object 'base' of the Tk()

base.geometry("550x550") #Using the Geometry method to the form certain dimensions

base.title('Registration form') #Using title method to give the title to the


window

roww=0
columnn=5

lbl_0 = Label(base, text="Registration form", width=20,font=("bold",20)) #Now, we


will use 'Label' method to add widget in the Registration Form and also use place()
method to set their positions.
lbl_0.grid(row=0+roww,column=3+columnn) #the place method in tkinter module helps
user to set the geometry, that is, the dimensions of a certain widget by placing
them at a certain position

lbl_1 =Label(base, text= "FullName", width=20,font=("bold",10))


lbl_1.grid(row=2+roww,column=3+columnn)

fullname=StringVar()
enter_1 = Entry(base,textvariable=fullname) #Using Enrty widget to make a text
entry box for accepting the input string in text from user.
enter_1.grid(row=1+roww,column=5+columnn)

lbl_2 =Label(base, text= "Address", width=20,font=("bold",10))


lbl_2.grid(row=3+roww,column=3+columnn)

enter_2 = Text(base,height=2,width=20) #Using Enrty widget to make a text entry


box for accepting the input string in text from user.
enter_2.grid(row=3+roww,column=5+columnn)

lbl_3 = Label(base, text="Email", width=20,font=("bold",10))


lbl_3.grid(row=4+roww,column=3+columnn)

email=StringVar()
enter_3 = Entry(base,textvariable=email) #Using Enrty widget to
make a text entry box for accepting the input string in text from user.
enter_3.grid(row=4+roww,column=5+columnn)

lbl_3_1 = Label(base, text="Password", width=20,font=("bold",10))


lbl_3_1.grid(row=6+roww,column=3+columnn)
password=StringVar()
enter_3_1 = Entry(base,show="*",textvariable=password) #Using
Enrty widget to make a text entry box for accepting the input string in text from
user.
enter_3_1.grid(row=6+roww,column=5+columnn)

lbl_4 = Label(base, text="Gender", width=20,font=("bold",10)) #Using 'Label'


widget to create Gender label and using place() method to set its position.
lbl_4.grid(row=8+roww,column=3+columnn)

vars = IntVar() #Using variable 'vars' to store the integer value, which by deault
is 0

Radiobutton(base, text="Male", padx= 5, variable= vars,


value=1).grid(row=8+roww,column=5+columnn) #Using Radio button widget to create an
option choosing button and using place() method to set its position.
Radiobutton(base, text="Female", padx= 20, variable= vars,
value=2).grid(row=8+roww,column=6+columnn)

lbl_5=Label(base, text ="Country", width=20,font=("bold",11)) #Using 'Label'


widget to create Countries label and using place() method, set its position.
lbl_5.grid(row=10,column=3+columnn)

list_of_cntry=[ 'India' ,'Canada' , 'US' ,'Germany' ,'UK'] #this creates list of


countries available in the dropdown list.

cv = StringVar() #the variable 'cv' is


introduced to store the String Value, which by default is (empty) ""
drplist = OptionMenu(base, cv, *list_of_cntry)
drplist.config(width=15)
cv.set('Select your Country')
drplist.grid(row=10,column=5+columnn)

lbl_6=Label(base, text="Language", width=20,font=('bold',10)) #Using 'Label'


widget to create Language label and using place() method, set its position.
lbl_6.grid(row=12,column=3+columnn)

vars1=tk.IntVar() #the new variable 'vars1' is created to


store Integer Value, which by default is 0.
Checkbutton(base,text="English", variable =
vars1).grid(row=12+roww,column=5+columnn) #Using the Checkbutton widget to create
a button and using place() method to set its position.

""" correct code to insert image in window


image1 = Image.open(r"image.jpg")
image1 = image1.resize((240, 240))
image1 = ImageTk.PhotoImage(image1)
label4 = tk.Label(image=image1)
label4.grid(row=13,column=8+columnn)
label5 = tk.Label(image=image1)
label5.grid(row=13,column=8+columnn)

"""

vars2=tk.IntVar()
Checkbutton(base,text="German", variable=vars2).grid(row=12,column=6+columnn)
#Using the Checkbutton widget to create a button and using place() method to set
its position.
def submit():
f_name=fullname.get()
add=enter_2.get("1.0","end") # entire content get("1.0","end") , 1st line
get("1.0","2.0") , third chracater get("2.2","2.3")
email1=email.get()
password1=password.get()
radio=vars.get()
check1=vars1.get()
check2=vars2.get()
droplist_select=cv.get()
print("Full Name",f_name)
print("Address",add)
print("Email ",email1)
print("Password ",password1)
print("Radio button ",radio)
print("drop list selection : ",droplist_select)
print(check1,check2)
if check2>0:
print("German OK")
elif check1>0:
print("English OK")

def open_img():
# Select the Imagename from a folder
x = openfilename()
print("File Path ",x)
# opens the image
img = Image.open(x)

# resize the image and apply a high-quality down sampling filter


img = img.resize((250, 250), Image.LANCZOS)

# PhotoImage class is used to add image to widgets, icons etc


img = ImageTk.PhotoImage(img)

# create a label
panel = Label(base, image = img)

# set the image as img


panel.image = img
panel.grid(row=15,column=5+columnn)
lbl =Label(base, text= x ,wraplength=200)
lbl.grid(row=17+roww,column=5+columnn)

def openfilename():

# open file dialog box to select image


# The dialogue box has a title "Open"
filename = filedialog.askopenfilename(title ='pen')
return filename

# Create a button and place it into the window using grid layout
btn = Button(base, text ='open image', command =
open_img).grid(row=18,column=5+columnn)

Button(base, text='Submit' , width=20,


bg="black",fg='white',command=submit).grid(row=19,column=5+columnn) #Using the
Button widget, we get to create a button for submitting all the data that has been
entered in the entry boxes of the form by the userbase.mainloop() #Calling the
mainloop method to execute the entire program.

You might also like