繁体   English   中英

Tkinter - 显示没有标题栏和屏幕键盘的全屏应用程序 (Linux)

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

我正在尝试在树莓派上创建一个全屏 tkinter 应用程序。 该应用程序需要有一个屏幕键盘(它在触摸屏上使用)。 我还希望没有标题栏(我不希望人们能够关闭应用程序,而且它看起来更干净)。 除了使用 zoomed 属性的标题栏之外,我已经能够完成所有这些工作,但它不能与我发现的任何其他删除标题栏的方法结合使用。 我使用的键盘是带有 raspbian 的 raspberry pi 3B+ 的 florence。 以下是我尝试过的案例。

覆盖重定向和全屏属性不允许屏幕键盘工作(它在应用程序后面打开)。

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.我认为这是因为该应用程序落后于 Python)。 这与 root.geometry 结合使用以全屏显示应用程序。

我能够找到两个类似的堆栈溢出问题在 tkinter 中使用屏幕键盘上的文本更新条目小部件,以及如何在 linux LXDE 上删除带有 tkinter 的标题栏或属性? . 第一个问题不需要全屏(这是我当前代码所在的位置),第二个问题不需要键盘。

    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()

有一种解决方法可以使用 splash 属性:您可以将条目上的单击绑定到entry.focus_force() ,然后您可以输入条目。 这是一个小例子:

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()

注意:我使用了 class 绑定到tk.Entry

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

使其适用于程序中的所有tk.Entry 但是,如果想使用不同的 class 小部件,例如ttk.Entry ,则必须将 class 绑定修改为

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

其中<class name>将是 ttk.Entry 的“ tk.Text ”, ttk.Entry的“TCombobox”或ttk.Combobox的“Text”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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