简体   繁体   中英

Tkinter - Displaying a fullscreen app without a title bar and with an on screen keyboard (Linux)

I am trying to create a fullscreen tkinter application on a raspberry pi. The application needs to have an on screen keyboard (it's being used on a touchscreen). I would also like there to not be a title bar (I don't want people to be able to close the app, plus it looks cleaner). I've been able to get all of that working except for the title bar using the zoomed attribute, but it can't be combined with any of the other methods I've found to remove the title bar. The keyboard that I am using is florence with a raspbian based raspberry pi 3B+. Below are the cases that I've tried.

Overrideredirect and fullscreen attributes don't allow the onscreen keyboard to work (it opens behind the app).

The splash attribute was very close to working, the issue was my Entry widgets didn't work (when I clicked on them the cursor wouldn't pop up, I could actually tab back to python and the cursor popped up but typed in python. I think this was because the app was behind Python). This was used in combination with the root.geometry to fullscreen the app.

I was able to find two similar stack overflow questions Updating entry widget using text from onscreen keyboard in tkinter and How do I remove the title bar with tkinter on linux LXDE without overrideredirect or attributes? . The first question doesn't require fullscreen (this is where I am at with my current code) and the second doesn't require a keyboard.

    root = tk.Tk()
    root.attributes('-zoomed', True)

    #width = root.winfo_screenwidth()
    #height = root.winfo_screenheight()
    #root.geometry("%dx%d+0+0" % (width, height))
    #root.wm_attributes('fullscreen', True)
    #root.overrideredirect(True)
    #root.attributes('-type', 'splash')
    root.mainloop()

There is a workaround to be able to use the splash attribute: you can bind the click on the entry to entry.focus_force() which then allows you to type in the entry. Here is a small example:

import tkinter as tk

root = tk.Tk()
root.attributes("-fullscreen", True)
root.attributes("-type", "splash")

root.bind_class("Entry", "<1>", lambda ev: ev.widget.focus_force())

entry = tk.Entry(root)
entry.pack()
tk.Button(root, text="Close", command=root.destroy).pack()
root.mainloop()

Note : I used a class binding to the tk.Entry :

root.bind_class("Entry", "<1>", lambda ev: ev.widget.focus_force())

so that it applies to all the tk.Entry in the program. However, if one wants to use a different class of widget, eg ttk.Entry , the class binding has to be modified to

root.bind_class(<class name>, "<1>", lambda ev: ev.widget.focus_force())

where <class name> will be "TEntry" for ttk.Entry , "TCombobox" for ttk.Combobox or "Text" for tk.Text .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM