Sep-18-2024, 07:45 AM
I have created a Tkinter form with the help of Figma/Tkinter.Designer. On Windows (Python 3.12) it works Ok. When I tried it on Linux Armbian/Bookworm (Python 3.11), I encountered an issue with the form's input field: when I clicked on it, it did not get focus, so I could not input anything on it. There are no errors reported at all.
So, to demonstrate the issue I left on the form just an input with its event handler and a button with its handler. I don't know how even to begin troubleshooting ...
https://otalado.eu/Tkinter/entry.png
https://otalado.eu/Tkinter/ok.png
So, to demonstrate the issue I left on the form just an input with its event handler and a button with its handler. I don't know how even to begin troubleshooting ...
import os, sys #import socket from pathlib import Path from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage myPath = os.path.dirname(os.path.abspath(sys.argv[0])) ASSETS_PATH = myPath + "/assets/frame0" def relative_to_assets(path: str) -> Path: return ASSETS_PATH / Path(path) maxhours = 12 posx = 1700 posy = 500 entryFont = ("Consolas", 10, "bold") def skeyevent(e): # allow digits, 2 characters long s = seconds.get("1.0", "end-1c") count = len(s) if e.char.isdigit(): count += 1 if count > 2: # and e.keysym not in {'BackSpace', 'Delete'}: seconds.delete("1.0", "end") s = s[0:2] seconds.insert("end-1c", str(s).rjust(2, "0")) return("break") if not ( e.char.isdigit() or e.keysym == "Delete" or e.keysym == "BackSpace" ): return "break" def okClicked(): ss = seconds.get("1.0", "end-1c") if ss=='': s=0 else: s = int(ss) if s > 59: s = 59 seconds.delete("1.0", "end") seconds.insert("end-1c", str(s).rjust(2, '0')) print(f"set,{str(s).rjust(2, "0")}") #quit() def exitClicked(): quit() window = Tk() window.geometry(f"160x123+{posx}+{posy}") window.overrideredirect(True) window.attributes("-topmost", True) window.configure(bg="#12707D") canvas = Canvas( window, bg="#12707D", height=123, width=160, bd=0, highlightthickness=0, relief="ridge", ) canvas.place(x=0, y=0) canvas.create_rectangle(1.0, 28.0, 159.0, 122.0, fill="#D9D9D9", outline="") canvas.create_text( 4.0, 100.0, anchor="nw", text="Seconds", fill="#000000", font=("SegoeUI", 10 * -1,"bold"), ) imgSeconds = PhotoImage(file=relative_to_assets("entry.png")) seconds_bg = canvas.create_image(64.0, 106.0, image=imgSeconds) seconds = Text(bd=0, bg="#FFFFFF", fg="#000716", highlightthickness=0, font= entryFont) seconds.place(x=55.0, y=95.0, width=18.0, height=20.0) seconds.bind("<Key>", skeyevent) imgOk = PhotoImage(file=relative_to_assets("ok.png")) buttonOk = Button( image=imgOk, borderwidth=0, highlightthickness=0, command=lambda: okClicked(), relief="flat", ) buttonOk.place(x=83.0, y=33.0, width=70.0, height=22.0) canvas.create_text( 48.0, 8.0, anchor="nw", text="Enter Time", fill="#FFFFFF", font=("Inter Bold", 12 * -1), ) window.resizable(False, False) window.mainloop()The script expects to find following two pictures in that Assets folder:
https://otalado.eu/Tkinter/entry.png
https://otalado.eu/Tkinter/ok.png