首页 > 解决方案 > PyGTKDeprecationWarning:我错过了什么?

问题描述

我的代码工作得很好,但是当我运行脚本时,我在终端中收到了这个警告。我错过了什么?

abc.py:10: PyGTKDeprecationWarning: Using positional arguments with the GObject constructor has been deprecated. Please specify keyword(s) for "label" or use a class specific constructor. See: https://wiki.gnome.org/PyGObject/InitializerDeprecations
actor_act = Gtk.Button("Click Here")

脚本名称:abc.py

实际代码:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

def actor(button):
    print('Simple Button')

boxy = Gtk.Window(title="Hello")
boxy.set_default_size(500,500)
actor_act = Gtk.Button("Click Here")
boxy.add(actor_act)

actor_act.connect("clicked", actor)
boxy.connect("destroy", Gtk.main_quit)

boxy.show_all()
Gtk.main()

标签: pythonpython-3.xgtk

解决方案


Gtk.按钮:

类:new_with_label(标签)

使用包含给定文本的 GtkLabel 子项创建 GtkButton 小部件。

参数: label #你希望 GtkLabel 保存的文本。

返回: 新创建的 GtkButton 小部件。

Gtk.Button.new_with_label("Click Here")

推荐阅读