Wie kann ich den GTK Entry Wert auslesen
Verfasst: Samstag 22. Juni 2019, 15:09
Guten Tag,
ich habe eine kleine App die so gestartet wird:
Dann in der MainWindow Klasse wird ein Fenster erstellt mit einem Menübutton:
Die Funktion on_menubutton_click erstellt dann ein custom dialog.
Jetzt würde ich gerne in dieser Funktion, set_company_data den entsprechenden Inhalt von dem Entry abgreifen.
Doch mit diesem Teil bekomme ich diesen Fehler:
Wie kann ich jetzt diesen Inhalt abfragen.
ich habe eine kleine App die so gestartet wird:
Code: Alles auswählen
class Invoicy(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self)
def do_activate(self):
win = MainWindow(self)
win.show_all()
def do_startup(self):
Gtk.Application.do_startup(self)
app = Invoicy()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
Code: Alles auswählen
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, app):
Gtk.Window.__init__(self, title="Invoicy", application=app)
self.set_border_width = 10
self.set_default_size(800, 600)
header_bar = Gtk.HeaderBar()
header_bar.set_show_close_button(True)
header_bar.props.title = "Invoicy"
self.set_titlebar(header_bar)
menubutton = Gtk.Button()
image = Gtk.Image.new_from_gicon(Gio.ThemedIcon(name="open-menu"), Gtk.IconSize.LARGE_TOOLBAR)
menubutton.add(image)
menubutton.connect("clicked", self.on_menubutton_click)
header_bar.pack_end(menubutton)
Code: Alles auswählen
def on_menubutton_click(self, widget):
dialog = Gtk.Dialog()
dialog.set_default_size(300, 300)
dialog.set_transient_for(self)
dialog.set_modal(True)
grid = Gtk.Grid(column_spacing=10, row_spacing=10)
grid.props.margin_left = 20
grid.props.margin_right = 20
grid.props.margin_top = 20
grid.props.margin_bottom = 20
companycountry_label = Gtk.Label("Country")
companycountry_entry = Gtk.Entry()
dialog.add_button(button_text="Save", response_id=Gtk.ResponseType.OK)
dialog.connect("response", self.set_company_data)
box = dialog.get_content_area()
box.add(grid)
dialog.show_all()
Doch mit diesem Teil bekomme ich diesen Fehler:
AttributeError: 'MainWindow' object has no attribute 'companycountry_entry'
Code: Alles auswählen
def set_company_data(self, widget, event):
print(self.companycountry_entry.get_text())
widget.destroy()