#!/usr/bin/python
# -*- coding: utf-8 -*-
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Handler:
def button_is_clicked(self, button):
ouraboutwindow.run()
ouraboutwindow.hide()
def enter_button_clicked(self, button):
print ourentry.get_text() + ourcomboboxtext.get_active_text()
builder = Gtk.Builder()
builder.add_from_file("ui.glade")
builder.connect_signals(Handler())
ournewbutton = builder.get_object("button1")
window = builder.get_object("window1")
ourcomboboxtext = builder.get_object("comboboxtext1")
default_text = [" World ", " Earth ", " All "]
for x in default_text:
ourcomboboxtext.append_text(x)
ourcomboboxtext.set_active(0)
ourentry = builder.get_object("entry1")
ourentry.set_max_length(15)
ourentry.set_placeholder_text("Enter A Text Here..")
ouraboutwindow = builder.get_object("aboutdialog1")
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main
我正在尝试学习 glade 界面中的小部件,我在其中创建了一个文本条目、一个组合框和一个按钮。但是组合框给了我一些错误。
在这里,我将在文本输入中输入一些内容,然后从组合框中选择一些内容,并将其一起打印在 shell 中。请帮忙。