GUI.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import customtkinter as ctk
  2. import json
  3. from PIL import Image, ImageTk
  4. import asyncio
  5. from bleak import BleakScanner
  6. from bleak import BleakClient
  7. target_name = "Long name works now"
  8. SERVICE_UUID= "d86aecf2-d87d-489f-b664-b02de82b2fc0"
  9. CHARACTERISTIC_UUID= "d86aecf2-d87d-489f-b664-b02de82b2fc0"
  10. async def connect():
  11. target_address = None
  12. devices = await BleakScanner.discover()
  13. for d in devices:
  14. print(d)
  15. if target_name == d.name:
  16. target_address = d.address
  17. print("found target {} bluetooth device with address {} ".format(target_name,target_address))
  18. break
  19. else:
  20. print("could not find device")
  21. return target_address
  22. #function that will recive the ESP32 data
  23. def getCurrentScore():
  24. print(30)
  25. #than do math to figure out power level
  26. currentScore = getCurrentScore()
  27. highestScore = 0
  28. if currentScore < highestScore :
  29. highestScore = currentScore
  30. f = open("scores.txt", "rw")
  31. f.write(highestScore)
  32. async def main():
  33. await connect()
  34. ctk.set_appearance_mode("System") # Modes: system (default), light, dark
  35. ctk.set_default_color_theme("blue") # Themes: blue (default), dark-blue, green
  36. app = ctk.CTk() # create CTk window like you do with the Tk window
  37. app.geometry("1440x1024")
  38. canvas = ctk.CTkCanvas(app, width=500, height=480,highlightthickness=0,)
  39. canvas.config(background="white")
  40. canvas.place(x=0,y=0)
  41. names = ["one","two","three","four","five"]
  42. scores = [1,2,3,4,5]
  43. def placeLeaderboard():
  44. canvas.create_rectangle(0, 0, 500, 500, fill="grey20", width=2) #grey14 to match background
  45. intx = 0
  46. inty = 80
  47. for i in range(len(names)):
  48. label1 = ctk.CTkLabel(width=249,height=79,text_color="white",text=names[i], font=("Arial",30),master=app)
  49. label1.place(x=intx,y=inty)
  50. label2 = ctk.CTkLabel(width=249,height=79,text_color="white",text=scores[i], font=("Arial",30),master=app)
  51. label2.place(x=intx+250,y=inty)
  52. inty+=80
  53. LEADERBOARD = ctk.CTkLabel(width=499,height=79,text_color="white",text="Leaderboard", font=("Arial",50),master=app)
  54. LEADERBOARD.place(x=0,y=0)
  55. StartButton = ctk.CTkButton(width=400,height=150,text="START",fg_color="green",corner_radius=50,font=("Arial",50),text_color="gray99",master=app)
  56. StartButton.place(x=50,y=600)
  57. ResetButton = ctk.CTkButton(width=400,height=150,text="RESET",fg_color="orange2",corner_radius=50,font=("Arial",50),text_color="gray99", master=app)
  58. ResetButton.place(x=50,y=800)
  59. scoreTitle = ctk.CTkLabel(width=50,height=20,text_color="white",text="Current Score:", font=("Arial",50),master=app)
  60. scoreTitle.place(x=600, y=20)
  61. scoreLabel = ctk.CTkLabel(width=50,height=20,text_color="white",text=currentScore, font=("Arial",50),master=app)
  62. scoreLabel.place(x=740, y=100)
  63. nameEntry = ctk.CTkEntry(width=350,height=50,master=app,font=("Arial",50))
  64. nameEntry.place(x=600,y=200)
  65. nameEntryButton = ctk.CTkButton(width=50,height=50,text="ENTER",fg_color="green",font=("Arial",20),text_color="gray99", master=app)
  66. nameEntryButton.place(x=980,y=205)
  67. image = Image.open("./Bell Drawing.png")
  68. photo = ImageTk.PhotoImage(image)
  69. image_label = ctk.CTkLabel(image=photo,text="",width=20, master=app)
  70. image_label.place(x=1200,y=0)
  71. dinger = ctk.CTkLabel(width=40,height=30,text="",fg_color="gray77",master=app)
  72. dinger.place(x=1405,y=900)
  73. placeLeaderboard()
  74. #label = customtkinter.CTkLabel(app, text=f"Current Highest Record is: {highestRecord} | this was acomplished by: {highestRecordName}", fg_color="brown")
  75. #progressbar = customtkinter.CTkProgressBar(app, height=300,orientation="vertical",width=40,fg_color="blue",progress_color="green",mode='determinate')
  76. #progressbar.set(float(f"0.{highestRecord}"))
  77. #label.grid(column=0,row=0)
  78. #progressbar.grid(column=25,row=8)
  79. asyncio.run(main())
  80. app.mainloop()