Skip to content
This repository was archived by the owner on Dec 6, 2025. It is now read-only.
This repository was archived by the owner on Dec 6, 2025. It is now read-only.

Tkinter GUI #41

@kaitoxakimoto

Description

@kaitoxakimoto

it's a very very simple prototype (in fact, i declare the use of my bulb's mac in the first declaration) but i think the use of Tkinter could be very useful to implement!

from tkinter import *
from magicblue import MagicBlue

#CHANGE THE BULB MAC HERE
bulb_mac_address = 'F8:1D:78:60:8E:0F'
bulb = MagicBlue(bulb_mac_address, 10) # Replace 9 by whatever your version is (default: 7)
bulb.connect()

def switch():
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
		inf=bulb.get_device_info()
	if inf["on"]:
		bulb.turn_off()
	else:
		bulb.turn_on()
	
def change_red(re):
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	color=map(int,(r.get(),g.get(),b.get()))
	bulb.set_color(color)

def change_green(gr):
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	color=map(int,(r.get(),g.get(),b.get()))
	bulb.set_color(color)

def change_blue(bl):
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	color=map(int,(r.get(),g.get(),b.get()))
	bulb.set_color(color)
	
def change_bright(br):
	global first
	if first:
		first = False
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	bulb.set_warm_light(bright.get()/255.0)	
	
	
	
w = Tk()	
	
#Models

r=IntVar()
g=IntVar()
b=IntVar()
bright=IntVar()

#First Check
inf=bulb.get_device_info()
r.set(inf["r"])
g.set(inf["g"])
b.set(inf["b"])
bright.set(inf["brightness"])
first=True

#Power Button

switch=Button(w,text="On / Off",command=switch)
switch.pack()

#First Frame

color_frame=Frame(w)
color_frame.pack()

#RGB

rgb_frame=Frame(color_frame,bd=10)
rgb_frame.grid(row=0,column=0)

red=Scale(rgb_frame, variable = r,orient=HORIZONTAL,to = 255, command = change_red, resolution = 5)
Label(rgb_frame,text="Red").pack()
red.pack()

green=Scale(rgb_frame, variable = g,orient=HORIZONTAL,to = 255, command = change_green, resolution = 5)
Label(rgb_frame,text="Green").pack()
green.pack()

blue=Scale(rgb_frame, variable = b , orient = HORIZONTAL , to = 255, command = change_blue, resolution = 5)
Label(rgb_frame,text="Blue").pack()
blue.pack()

#Bright

bright_frame=Frame(color_frame,bd=10)
bright_frame.grid(row=0,column=1)

bright=Scale(bright_frame, variable = bright , orient = VERTICAL ,from_ = 255, to = 0	, command = change_bright, resolution = -5)
Label(bright_frame,text="Brightness").pack()
bright.pack()



w.mainloop()

bulb.disconnect()

it looks like this for now:
image

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions