您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – GTK标签包装在一个对话框中

5b51 2022/1/14 8:23:11 python 字数 3003 阅读 579 来源 www.jb51.cc/python

我正在尝试创建一个带有标签的不可调整大小的对话框.这个标签有很多文字,所以我想要它包装而不会使对话格宽阔. 出于某种原因,我无法找到让GTK允许这种情况发生的方法.我甚至找不到在对话框上设置最大宽度的方法,这将是很好的. 这是我的意思的一个运行的例子: #!/usr/bin/env python #-*- coding:utf-8 -*- from gi.repository import Gt

概述

出于某种原因,我无法找到让GTK允许这种情况发生的方法.我甚至找不到在对话框上设置最大宽度的方法,这将是很好的.

这是我的意思的一个运行的例子:

#!/usr/bin/env python
#-*- coding:utf-8 -*-

from gi.repository import Gtk

class DialogExample(Gtk.Dialog):

    def __init__(self,parent):
        Gtk.Dialog.__init__(self,"My Dialog",parent,(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_OK,Gtk.ResponseType.OK))

        self.set_default_size(150,100)
        self.set_resizable(False)

        label = Gtk.Label("This is a dialog to display additional information,with a bunch of text in it just to make sure it will wrap enough for demonstration purposes")
        label.set_line_wrap(True)

        Box = self.get_content_area()
        Box.add(label)
        self.show_all()

class DialogWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self,title="Dialog Example")

        self.set_default_size(250,200)


        button = Gtk.Button("Open dialog")
        button.connect("clicked",self.on_button_clicked)

        self.add(button)

    def on_button_clicked(self,widget):
        dialog = DialogExample(self)
        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            print "The OK button was clicked"
        elif response == Gtk.ResponseType.CANCEL:
            print "The Cancel button was clicked"

        dialog.destroy()

win = DialogWindow()
win.connect("delete-event",Gtk.main_quit)
win.show_all()
Gtk.main()
label = Gtk.Label("This is a dialog to display additional information,with a bunch of text in it just to make sure it will wrap enough for demonstration purposes")
label.set_line_wrap(True)
label.set_size_request(250,-1) # 250 or whatever width you want. -1 to keep height automatic

table = Gtk.Table(1,1,False)
table.attach(label,Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL)

这应该够了吧

总结

以上是编程之家为你收集整理的python – GTK标签包装在一个对话框中全部内容,希望文章能够帮你解决python – GTK标签包装在一个对话框中所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶