You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# window=tkinter.Tk() # Tk is constructor(it will create the window)
13
+
# window.mainloop() # mainloop is method
14
+
# these three line will return window when we will run
15
+
# we must write these above three line when we want to make GUI application using Tkinter.
16
+
17
+
18
+
19
+
20
+
# import tkinter
21
+
# window=tkinter.Tk()
22
+
# window.title("GUI") # this will change the name of window
23
+
# window.mainloop()
24
+
25
+
26
+
27
+
28
+
29
+
# from tkinter import * # importing tkinter libray in other way
30
+
# window=Tk()
31
+
# window.title("GUI")
32
+
# window.mainloop()
33
+
34
+
35
+
36
+
37
+
38
+
# starter code
39
+
importtkinterastk
40
+
fromtkinterimportttk
41
+
window=tk.Tk()
42
+
window.title("GUI")
43
+
44
+
45
+
# create lables ---->lables can be a text, or lable of any thing(stuff)
46
+
47
+
# widgets(label, button, radio buttons) ---> available in tk and ttk library
48
+
# we can use tk or ttk for widgets but ttk widgets are more attractive in terms of design
49
+
50
+
# name_label=tk.Label(window,text="Enter Your name : ")
51
+
name_lable=ttk.Label(window,text="Enter Your name : ")
52
+
name_lable.grid(row=0,column=0,sticky=tk.W) # # there are two methos for set location of widget 1)pack (name_label.pack()), 2)grid(name_lable.grid(row=0,column=0))
53
+
54
+
email_lable=ttk.Label(window,text="Enter your E-mail : ")
55
+
email_lable.grid(row=1,column=0,sticky=tk.W)
56
+
57
+
age_label=ttk.Label(window,text="Enter your age : ")
58
+
age_label.grid(row=2,column=0,sticky=tk.W) # stiky=tk.W is used for start line from lest side window(stick leble on WEST side)
gender_combo=ttk.Combobox(window,width=15, textvariable=gender_var,state='readonly') # state is for make comobo box read only, it means we can not write inside combo box
91
+
gender_combo['values']=('Male','Female','Other')
92
+
gender_combo.current(0) # it is for set the value in comobo box
check_button=ttk.Checkbutton(window,text="check if you want to subscribe to our newsletter",variable=check_var)
113
+
check_button.grid(row=5,columnspan=3) # columnspan is used for taking column without affecting other one. If we write only column we got affected GUI in terms of space.
114
+
115
+
116
+
117
+
118
+
119
+
# create button
120
+
# def action():
121
+
# user_name=name_var.get() # here, get() method is used for getting value of variable
122
+
# user_mail=email_var.get()
123
+
# user_age=age_var.get()
124
+
# user_gender=gender_var.get()
125
+
# user_occuption=occuption_var.get()
126
+
# # for check box, beccause check box will return 0 or 1.
# # these three lines for deleteing values from edit box after clicking on submit button
136
+
# name_entry.delete(0,tk.END)
137
+
# email_entry.delete(0,tk.END)
138
+
# age_entry.delete(0,tk.END)
139
+
140
+
# # when we want to change color of name lable after clicking on submit button
141
+
# name_lable.configure(foreground="Blue") # here we can use color code instead of color name
142
+
# # name_lable.configure(background="Blue")
143
+
# # window.configure(background="Pink") # change background color of window
144
+
# # submit_button.configure(foreground="Blue") # in this we will get error, for doing this we have to use stylish, otherwise use tk insted of ttk in submit_button=tk.Button(.....)
145
+
146
+
147
+
148
+
# write into CSV
149
+
fromcsvimportDictWriter
150
+
importos
151
+
defaction():
152
+
user_name=name_var.get() # here, get() method is used for getting value of variable
153
+
user_mail=email_var.get()
154
+
user_age=age_var.get()
155
+
user_gender=gender_var.get()
156
+
user_occuption=occuption_var.get()
157
+
# for check box, beccause check box will return 0 or 1.
0 commit comments