![](/img/trans.png)
[英]How do I remove the title bar with tkinter on linux LXDE without overrideredirect or attributes?
[英]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.