Gtk 按钮内边框

发布于 2024-12-06 02:03:14 字数 98 浏览 1 评论 0原文

我向 HBox 添加了一个按钮,且 Expand 等于 False,但我希望按钮的标签和边框之间有更大的间距。我认为它是“内边框”属性,但它是只读的。我怎样才能将它设置为例如4px?

I add a button to HBox, with expand equal to False, but I want the button to have more spacing between its label and border. I assume it is "inner-border" property, but it is read-only. How can I set it to e.g. 4px?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

财迷小姐 2024-12-13 02:03:14

gtk.Label 是 gtk.Misc 的子类,它具有 set_padding 方法。如果你从 gtk.Button 中获取标签,那么你可以在它上面调用 set_padding 。

你可以这样做:

label = gtk.Label("Hello World")
button = gtk.Button()

/* Add 10 pixels border around the label */
label.set_padding(10, 10)

/* Add the label to the button */
button.add(label)

/* Show the label as the button will assume it is already shown */
label.show()

gtk.Label is a subclass of gtk.Misc which has the method set_padding. If you get the label out of the gtk.Button then you can just call set_padding on it.

You could do something like:

label = gtk.Label("Hello World")
button = gtk.Button()

/* Add 10 pixels border around the label */
label.set_padding(10, 10)

/* Add the label to the button */
button.add(label)

/* Show the label as the button will assume it is already shown */
label.show()
挽你眉间 2024-12-13 02:03:14

错误答案:

您正在寻找的内容称为“填充”。当您将按钮添加到容器时,例如通过调用 gtk.Box.pack_start,只需将padding参数设置为正整数即可。

更新:

似乎我误读了这个问题。在这种情况下,我的猜测是你应该使用 gtk_widget_modify_style,因为 inner-border 是一个样式属性。您首先需要通过调用 gtk_widget_get_modifier_style。然后,您将能够使用 资源样式匹配规则

Wrong answer:

What you're looking for is called "padding". When you add your button to the container, for example by calling gtk.Box.pack_start, just set the padding parameter to a positive integer.

Update:

Seems I misread the question. In that case, my guess is that you're supposed to use gtk_widget_modify_style, as inner-border is a style property. You'll first get the style modifier you need by calling gtk_widget_get_modifier_style. You'll then be able to modify the style only for that button using the ressource styles matching rules.

抹茶夏天i‖ 2024-12-13 02:03:14

您可以使用 gtk 按钮的“inner-border”样式属性。

这里

In gtkrc file:

  style "button_style"
  {
   GtkButton::inner-border = {10,10,10,10}
  }
  class "GtkButton" style "button_style"

In .py file:

  gtk.rc_parse(rc_file_path + rc_file)

小代码片段[编辑]

是 gtkrc 文件中的

  style "button_style"
  {
   GtkButton::inner-border = {10,10,10,10}
  }
  widget "*.StyleButton" style "button_style" # apply style for specific name of widget


In .py file:

  gtk.rc_parse(rc_file_path + rc_file)

  #set name of button
  self.style_button.set_name('StyleButton')

:希望会有帮助。

you can use "inner-border" style property of gtk button.

here, small code snippets

In gtkrc file:

  style "button_style"
  {
   GtkButton::inner-border = {10,10,10,10}
  }
  class "GtkButton" style "button_style"

In .py file:

  gtk.rc_parse(rc_file_path + rc_file)

[Edit]

In gtkrc file:

  style "button_style"
  {
   GtkButton::inner-border = {10,10,10,10}
  }
  widget "*.StyleButton" style "button_style" # apply style for specific name of widget


In .py file:

  gtk.rc_parse(rc_file_path + rc_file)

  #set name of button
  self.style_button.set_name('StyleButton')

hope, it would be helpful.

娇纵 2024-12-13 02:03:14

我有时只是在标签中添加空格!

gtk.Button("  Label  ")

以获得一些间距。

希望这可以帮助你。

I sometimes just add spaces in the label !

gtk.Button("  Label  ")

to get some spacing.

Hope this could help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文