forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangeLabelDemo.py
47 lines (39 loc) · 1.78 KB
/
ChangeLabelDemo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from tkinter import * # Import tkinter
class ChangeLabelDemo:
def __init__(self):
window = Tk() # Create a window
window.title("Change Label Demo") # Set a title
# Add a label to frame1
frame1 = Frame(window) # Create and add a frame to window
frame1.pack()
self.lbl = Label(frame1, text = "Programming is fun")
self.lbl.pack()
# Add a label, an entry, a button, and two radio buttons to frame2
frame2 = Frame(window) # Create and add a frame to window
frame2.pack()
label = Label(frame2, text = "Enter text: ")
self.msg = StringVar()
entry = Entry(frame2, textvariable = self.msg)
btChangeText = Button(frame2, text = "Change Text",
command = self.processButton)
self.v1 = StringVar()
rbRed = Radiobutton(frame2, text = "Red", bg = "red",
variable = self.v1, value = 'R',
command = self.processRadiobutton)
rbYellow = Radiobutton(frame2, text = "Yellow",
bg = "yellow", variable = self.v1, value = 'Y',
command = self.processRadiobutton)
label.grid(row = 1, column = 1)
entry.grid(row = 1, column = 2)
btChangeText.grid(row = 1, column = 3)
rbRed.grid(row = 1, column = 4)
rbYellow.grid(row = 1, column = 5)
window.mainloop() # Create an event loop
def processRadiobutton(self):
if self.v1.get() == 'R':
self.lbl["fg"] = "red"
elif self.v1.get() == 'Y':
self.lbl["fg"] = "yellow"
def processButton(self):
self.lbl["text"] = self.msg.get() # New text for the label
ChangeLabelDemo() # Create GUI