from re import A, I import customtkinter as ctk import json from PIL import Image, ImageTk import time import asyncio from dobluetooth import connect, getData # This could probably go in dobluetooth.py try: from bleak.backends.winrt.util import allow_sta # tell Bleak we are using a graphical user interface that has been properly # configured to work with asyncio allow_sta() except ImportError: # other OSes and older versions of Bleak will raise ImportError which we # can safely ignore pass """ parse esp32 data string and make each axis and accell data its own varible then do math on all those varibles to give us ONE NUMBER from all six numbers """ def getCurrentScore(): #than do math to figure out power level return 30 names = [] scores = [] currentScore = getCurrentScore() highestScore = 100 highScoreName = "" if currentScore > highestScore : highestScore = currentScore f = open("scores.txt", "rw") f.write(str(highestScore) + highScoreName) scores.append(highestScore) names.append(highScoreName) ctk.set_appearance_mode("System") # Modes: system (default), light, dark ctk.set_default_color_theme("blue") # Themes: blue (default), dark-blue, green app = ctk.CTk() # create CTk window like you do with the Tk window app.geometry("1440x1024") canvas = ctk.CTkCanvas(app, width=250, height=250,highlightthickness=0,) canvas.config(background="white") canvas.place(x=0,y=0) def placeLeaderboard(): canvas.create_rectangle(0, 0, 500, 500, fill="grey20", width=2) #grey14 to match background intx = 0 inty = 60 for i in range(len(names)): label1 = ctk.CTkLabel(width=124,height=39,text_color="white",text=names[i], font=("Arial",15),master=app) label1.place(x=intx,y=inty) label2 = ctk.CTkLabel(width=124,height=39,text_color="white",text=scores[i], font=("Arial",15),master=app) label2.place(x=intx+125,y=inty) inty+=40 LEADERBOARD = ctk.CTkLabel(width=249,height=39,text_color="white",text="Leaderboard", font=("Arial",50),master=app) LEADERBOARD.place(x=0,y=0) StartButton = ctk.CTkButton(width=00,height=150,text="START",fg_color="green",corner_radius=50,font=("Arial",50),text_color="gray99",master=app) StartButton.place(x=50,y=300) ResetButton = ctk.CTkButton(width=00,height=150,text="RESET",fg_color="orange2",corner_radius=50,font=("Arial",50),text_color="gray99", master=app) ResetButton.place(x=50,y=500) scoreTitle = ctk.CTkLabel(width=50,height=20,text_color="white",text="Current Score", font=("Arial",50),master=app) scoreTitle.place(x=350, y=20) scoreLabel = ctk.CTkLabel(width=50,height=20,text_color="white",text=currentScore, font=("Arial",50),master=app) scoreLabel.place(x=500, y=100) nameEntry = ctk.CTkEntry(width=300,height=50,master=app,font=("Arial",50)) nameEntry.place(x=370,y=200) nameEntryButton = ctk.CTkButton(width=50,height=50,text="ENTER",fg_color="green",font=("Arial",20),text_color="gray99", master=app) nameEntryButton.place(x=670,y=205) image = Image.open("./BellDrawing.png") photo = ImageTk.PhotoImage(image) #ctkphoto = ctk.CTkImage(image) image_label = ctk.CTkLabel(image=photo,text="",width=10, master=app) image_label.place(x=800,y=0) dinger = ctk.CTkLabel(width=40,height=30,text="",fg_color="gray77",master=app) dinger.place(x=1405,y=900) placeLeaderboard() #label = customtkinter.CTkLabel(app, text=f"Current Highest Record is: {highestRecord} | this was acomplished by: {highestRecordName}", fg_color="brown") #progressbar = customtkinter.CTkProgressBar(app, height=300,orientation="vertical",width=40,fg_color="blue",progress_color="green",mode='determinate') #progressbar.set(float(f"0.{highestRecord}")) #label.grid(column=0,row=0) #progressbar.grid(column=25,row=8) async def runLoop(): target_address = await connect() if target_address is not None: async with BleakClient(target_address) as client: print(f"Connected: {client.is_connected}") while 1: try: data = await client.read_gatt_char(CHARACTERISTIC_UUID) datastr = data.decode('utf-8') #convert byte to str print("time: {} ||| numbers: {}".format(time.time(),convertToNumbers(datastr))) except Exception: print("failed to get data, restarting connection.") def data(): asyncio.run(getData()) app.after(1000,data) app.mainloop()