Python 带滚动和<;的Gtk笔记本更改页面;alt>+;1像firefox、chrome、epiphany
我搜索了一些关于如何做标题中的事情的例子。基本上,我使用gobject和Gtk编写了一个python程序,我有一个主窗口内有4页的笔记本 我喜欢让笔记本使用Python 带滚动和<;的Gtk笔记本更改页面;alt>+;1像firefox、chrome、epiphany,python,c,user-interface,gtk,usability,Python,C,User Interface,Gtk,Usability,我搜索了一些关于如何做标题中的事情的例子。基本上,我使用gobject和Gtk编写了一个python程序,我有一个主窗口内有4页的笔记本 我喜欢让笔记本使用+1+2+3+4以及鼠标滚动来更改页面。我在谷歌上搜索了一会儿,但没有找到合适的例子 如果有人在这个问题上有什么建议,我真的很感激你的帮助 PS:任何语言的示例都很好这将解决标签号切换问题 from gi.repository import Gtk tabs = Gtk.Notebook() tabs.set_scrollable(True
+1
+2
+3
+4
以及鼠标滚动来更改页面。我在谷歌上搜索了一会儿,但没有找到合适的例子
如果有人在这个问题上有什么建议,我真的很感激你的帮助
PS:任何语言的示例都很好这将解决标签号切换问题
from gi.repository import Gtk
tabs = Gtk.Notebook()
tabs.set_scrollable(True)
button = Gtk.Button()
button.set_label('hi!')
button.set_relief(Gtk.ReliefStyle.NONE)
#here we use a grid to allow more widgets in the tab label.
box = Gtk.Grid(orientation=Gtk.Orientation.HORIZONTAL)
box.add(button)
box.show_all()
#a general tab number switcher
def on_this_tab_clicked(button, tabs, pagenum):
tabs.set_current_page(pagenum)
#any button on a tab needs numbers in its callback argument
#as well as a argument for the tab object(Gtk.Notebook)
button.connect("clicked", on_this_tab_clicked, tabs, 0)
#Here we add the acclerator.
accels = Gtk.AccelGroup()
#parse it so it's easy to read
key, mod = Gtk.accelerator_parse("<Alt>1")
button.add_accelerator("activate", accels, key, mod, Gtk.AccelFlags.VISIBLE)
tab_content = Gtk.Label()
tab_content.set_text('hi!')
#place the box(Gtk.Grid) in the second argument of append_page
tabs.append_page(tab_content, box)
tabs.set_tab_reorderable(tab_content, True)
#do everything with successive buttons exactly like the first button
button2 = Gtk.Button()
button2.set_label('bye!')
button2.set_relief(Gtk.ReliefStyle.NONE)
box2 = Gtk.Grid(orientation=Gtk.Orientation.HORIZONTAL)
box2.add(button2)
box2.show_all()
button2.connect("clicked", on_this_tab_clicked, tabs, 1)
key2, mod2 = Gtk.accelerator_parse("<Alt>2")
button2.add_accelerator("activate", accels, key2, mod2, Gtk.AccelFlags.VISIBLE)
tab_content2 = Gtk.Label()
tab_content2.set_text('bye!')
tabs.append_page(tab_content2, box2)
tabs.set_tab_reorderable(tab_content2, True)
window = Gtk.Window()
window.set_default_size(200, 200)
window.add(tabs)
window.add_accel_group(accels)
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
从gi.repository导入Gtk
tabs=Gtk.Notebook()
tabs.set_可滚动(真)
button=Gtk.button()
按钮。设置标签('hi!')
按钮。设置浮雕(Gtk.ReliefStyle.NONE)
#在这里,我们使用一个网格来允许选项卡标签中有更多的小部件。
框=Gtk.网格(方向=Gtk.方向.水平)
框。添加(按钮)
box.show_all()
#一种通用的制表符转换程序
单击此选项卡上的def(按钮、选项卡、页面编号):
制表符。设置当前页面(pagenum)
#选项卡上的任何按钮在其回调参数中都需要数字
#以及选项卡对象(Gtk.Notebook)的参数
按钮。连接(“单击”,在此选项卡上单击,选项卡,0)
#这里我们添加了加速剂。
accels=Gtk.AccelGroup()
#对其进行分析,以便易于阅读
键,mod=Gtk.accelerator\u parse(“
这些链接很好。只需使用并翻译以下内容:
gtk_函数_名称(对象,参数)
进入:
gtk.object.function(args)这将解决标签号切换问题
from gi.repository import Gtk
tabs = Gtk.Notebook()
tabs.set_scrollable(True)
button = Gtk.Button()
button.set_label('hi!')
button.set_relief(Gtk.ReliefStyle.NONE)
#here we use a grid to allow more widgets in the tab label.
box = Gtk.Grid(orientation=Gtk.Orientation.HORIZONTAL)
box.add(button)
box.show_all()
#a general tab number switcher
def on_this_tab_clicked(button, tabs, pagenum):
tabs.set_current_page(pagenum)
#any button on a tab needs numbers in its callback argument
#as well as a argument for the tab object(Gtk.Notebook)
button.connect("clicked", on_this_tab_clicked, tabs, 0)
#Here we add the acclerator.
accels = Gtk.AccelGroup()
#parse it so it's easy to read
key, mod = Gtk.accelerator_parse("<Alt>1")
button.add_accelerator("activate", accels, key, mod, Gtk.AccelFlags.VISIBLE)
tab_content = Gtk.Label()
tab_content.set_text('hi!')
#place the box(Gtk.Grid) in the second argument of append_page
tabs.append_page(tab_content, box)
tabs.set_tab_reorderable(tab_content, True)
#do everything with successive buttons exactly like the first button
button2 = Gtk.Button()
button2.set_label('bye!')
button2.set_relief(Gtk.ReliefStyle.NONE)
box2 = Gtk.Grid(orientation=Gtk.Orientation.HORIZONTAL)
box2.add(button2)
box2.show_all()
button2.connect("clicked", on_this_tab_clicked, tabs, 1)
key2, mod2 = Gtk.accelerator_parse("<Alt>2")
button2.add_accelerator("activate", accels, key2, mod2, Gtk.AccelFlags.VISIBLE)
tab_content2 = Gtk.Label()
tab_content2.set_text('bye!')
tabs.append_page(tab_content2, box2)
tabs.set_tab_reorderable(tab_content2, True)
window = Gtk.Window()
window.set_default_size(200, 200)
window.add(tabs)
window.add_accel_group(accels)
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
从gi.repository导入Gtk
tabs=Gtk.Notebook()
tabs.set_可滚动(真)
button=Gtk.button()
按钮。设置标签('hi!')
按钮。设置浮雕(Gtk.ReliefStyle.NONE)
#在这里,我们使用一个网格来允许选项卡标签中有更多的小部件。
框=Gtk.网格(方向=Gtk.方向.水平)
框。添加(按钮)
box.show_all()
#一种通用的制表符转换程序
单击此选项卡上的def(按钮、选项卡、页面编号):
制表符。设置当前页面(pagenum)
#选项卡上的任何按钮在其回调参数中都需要数字
#以及选项卡对象(Gtk.Notebook)的参数
按钮。连接(“单击”,在此选项卡上单击,选项卡,0)
#这里我们添加了加速剂。
accels=Gtk.AccelGroup()
#对其进行分析,以便易于阅读
键,mod=Gtk.accelerator\u parse(“
这些链接很好。只需使用并翻译以下内容:
gtk_函数_名称(对象,参数)
进入:
gtk.object.function(args)首先,我在谷歌上搜索到了你的问题
然后我在谷歌上搜索了更多。这个资源指向我。它说:
要接收此信号,与小部件关联的GdkWindow需要启用GDK_SCROLL_掩码
我按照链接到GDK\u SCROLL\u MASK
找到了另一个MASKGDK\u SMOOTH\u SCROLL\u MASK
这就是解决方案:
from gi.repository import Gtk, Gdk
...
class MainWindow(Gtk.Window):
def __init__(self):
...
self.notebook = Gtk.Notebook()
self.notebook.add_events(Gdk.EventMask.SCROLL_MASK |\
Gdk.EventMask.SMOOTH_SCROLL_MASK)
self.notebook.connect('scroll-event', self.aaa)
def aaa(self, widget, event):
# I used `dir(event)` to find out `get_scroll_deltas()`
if event.get_scroll_deltas()[2] < 0:
self.notebook.prev_page()
else:
self.notebook.next_page()
从gi.repository导入Gtk、Gdk
...
类主窗口(Gtk.Window):
定义初始化(自):
...
self.notebook=Gtk.notebook()
self.notebook.add_事件(Gdk.EventMask.SCROLL_MASK|\
Gdk.EventMask.SMOOTH\u SCROLL\u MASK)
self.notebook.connect('scroll-event',self.aaa)
def aaa(自我、小部件、事件):
#我使用'dir(event)`查找'get\u scroll\u delta()`
if event.get\u scroll\u delta()[2]<0:
self.notebook.prev_page()
其他:
self.notebook.next_page()
祝你今天愉快:-)首先,我在谷歌上搜索到了你的问题
然后我在谷歌上搜索了更多。这个资源指向我。它说:
要接收此信号,与小部件关联的GdkWindow需要启用GDK_SCROLL_掩码
我按照链接到GDK\u SCROLL\u MASK
找到了另一个MASKGDK\u SMOOTH\u SCROLL\u MASK
这就是解决方案:
from gi.repository import Gtk, Gdk
...
class MainWindow(Gtk.Window):
def __init__(self):
...
self.notebook = Gtk.Notebook()
self.notebook.add_events(Gdk.EventMask.SCROLL_MASK |\
Gdk.EventMask.SMOOTH_SCROLL_MASK)
self.notebook.connect('scroll-event', self.aaa)
def aaa(self, widget, event):
# I used `dir(event)` to find out `get_scroll_deltas()`
if event.get_scroll_deltas()[2] < 0:
self.notebook.prev_page()
else:
self.notebook.next_page()
从gi.repository导入Gtk、Gdk
...
类主窗口(Gtk.Window):
定义初始化(自):
...
self.notebook=Gtk.notebook()
self.notebook.add_事件(Gdk.EventMask.SCROLL_MASK|\
Gdk.EventMask.SMOOTH\u SCROLL\u MASK)
self.notebook.connect('scroll-event',self.aaa)
def aaa(自我、小部件、事件):
#我使用'dir(event)`查找'get\u scroll\u delta()`
if event.get\u scroll\u delta()[2]<0:
self.notebook.prev_page()
其他:
self.notebook.next_page()
祝你今天愉快:-)嘿,伙计!我现在正试着做同样的事情。你解决了这个问题吗?我试着为笔记本中使用的标签设置加速器,但没有帮助。我将尝试深入研究这些文档,看看还有什么可以尝试的。您好!对不起,我忘了这件事,因为我找不到解决办法。我当时正在做一个内部公用事业的小项目,没有太多时间花在这上面。也许将来我也会遇到同样的问题。奇怪的是,我看到它在不同的程序中工作。。。Gnome终端和许多其他终端。我希望它是gtk+的内部功能。可能不是。嘿,伙计!我现在正试着做同样的事情。你解决了这个问题吗?我试着为笔记本中使用的标签设置加速器,但没有帮助。我将尝试深入研究这些文档,看看还有什么可以尝试的。您好!对不起,我忘了这件事,因为我找不到解决办法。我当时正在做一个内部公用事业的小项目,没有太多时间花在这上面。也许将来我也会遇到同样的问题。奇怪的是,我看到它在不同的程序中工作。。。Gnome终端和许多其他终端。我希望它是gtk+的内部功能。很可能不是。很抱歉投了反对票,但你的回答确实不足以解决OP的问题。您的第二个链接实际上指向一个为操作项(菜单和工具栏项)添加加速器的方法