Tutorial

Table Of Contents
112
'''
Use Tkinter's Button method to define a button. The button is on the root window. The name of the button is 'ON'. The
text color of the button is # E1F5FE. The background color of the button is # 0277BD. )function
'''
btn_on = tk.Button(root, width=8, text='ON', fg='#E1F5FE', bg='#0277BD', command=lights_on)
'''
Choose a location to place this button
'''
btn_on.place(x=15, y=15)
'''
The same method defines another key, the difference is that the text above the key is changed to 'OFF'. When the key is
pressed, the lights_off () function is called
'''
btn_off = tk.Button(root, width=8, text='OFF', fg='#E1F5FE', bg='#0277BD', command=lights_off)
btn_off.place(x=95, y=15)
'''
Finally open the message loop
'''
root.mainloop()
We first run the program in the Raspberry Pi, and then open the program on the PC (first run the server
and then the client).
Click 'ON', the light is on, and 'on' is printed in the terminal of the Raspberry Pi, indicating that the
program runs successfully.