Gtk3 Python-永久可见的搜索栏
我试图有一个永久可见的搜索栏小应用程序。Gtk3 Python-永久可见的搜索栏,python,gtk3,searchbar,Python,Gtk3,Searchbar,我试图有一个永久可见的搜索栏小应用程序。Gtk.SearchEntry的当前实现是,当您按下Esc时,搜索栏将从窗口中消失。我在下面的MWA中添加了一个事件处理程序,但当你按下Esc时,搜索栏会闪烁片刻,然后重新出现,这让我很苦恼。只要按住Esc,它实际上将保持不可见 import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk class AppWindow(Gtk.ApplicationWind
Gtk.SearchEntry
的当前实现是,当您按下Esc
时,搜索栏将从窗口中消失。我在下面的MWA中添加了一个事件处理程序,但当你按下Esc
时,搜索栏会闪烁片刻,然后重新出现,这让我很苦恼。只要按住Esc
,它实际上将保持不可见
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
class AppWindow(Gtk.ApplicationWindow):
def __init__(self):
super(AppWindow, self).__init__()
self.grid = Gtk.Grid()
self.add(self.grid)
self.searchbar = Gtk.SearchBar()
self.grid.attach(self.searchbar, 1, 1, 1, 1)
if not self.searchbar.get_search_mode():
self.searchbar.set_search_mode(True)
self.searchentry = Gtk.SearchEntry()
self.searchbar.connect_entry(self.searchentry)
self.searchbar.add(self.searchentry)
self.searchbar.set_show_close_button(False)
self.connect("key-release-event", self._on_key_release)
def _on_key_release(self, widget, event):
keyname = Gdk.keyval_name(event.keyval)
if keyname == 'Escape':
self.searchbar.set_visible(True)
self.searchbar.set_search_mode(True)
if event.state and Gdk.ModifierType.CONTROL_MASK:
if keyname == 'f':
self.searchbar.set_search_mode(True)
class Application(Gtk.Application):
def __init__(self):
super(Application, self).__init__()
def do_activate(self):
self.win = AppWindow()
self.win.show()
self.win.connect("delete-event", Gtk.main_quit)
self.win.show_all()
Gtk.main()
if __name__ == '__main__':
app = Application()
app.run()
有没有可能不让整个搜索栏闪烁,我只看到当前搜索文本消失而不闪烁?如果您希望搜索条目始终可见,请停止使用搜索栏。只需将SearchEntry
直接添加到您的容器中即可
class AppWindow(Gtk.ApplicationWindow):
def __init__(self):
super(AppWindow, self).__init__()
self.grid = Gtk.Grid()
self.add(self.grid)
self.searchentry = Gtk.SearchEntry()
self.grid.attach(self.searchentry, 1, 1, 1, 1)
self.connect("key-release-event", self._on_key_release)}
您可能需要设置一些边距或间距,以获得适合您的外观