Python Forum

Full Version: Text input OK on Windows, not working on linux
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 ...

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
I'm not sure about the rest as of yet but,
return ASSETS_PATH / Path(path) should be
return f'{ASSETS_PATH} / {Path(path)}'
or the like. You have a forward slash not in quotes.


I do not understand the need for all the return("break") either.
(Sep-18-2024, 08:40 AM)menator01 Wrote: [ -> ]I'm not sure about the rest as of yet but,
return ASSETS_PATH / Path(path) should be
return f'{ASSETS_PATH} / {Path(path)}'
or the like. You have a forward slash not in quotes.


I do not understand the need for all the return("break") either.

Hi, the two things you suspect are not the issue. I made a small app with just one entry and a button and played with it. It turns out that it works on Windows but not on Linux. When I removed the line:
window.overrideredirect(True)
to re-enable form to allow the title bar on the form, the whole thing started working Ok on Linux too.
Now I need to figure out how to hide the title bar without that "side effect".
window.overrideredirect(True)
is OK on Windows,
window.wm_attributes('-type', 'splash')
is OK on Linux.

I was unable to find a way to hide the title bar which would work on both without creating some issues. Fortunately, it is easy for Python to figure out on which OS it is running and adapt to it accordingly.
But if there is someone who knows if there is a way common for both OS's, I'd like to know howit