PythonGtk GUI programming in linux, pythongtkgui

Source: Internet
Author: User

PythonGtk GUI programming in linux, pythongtkgui

Installation:

$ Sudo apt install libgtk3 *

$ Sudo apt install glade

Then open glade for design.

Ui. glade

<? Xml version = "1.0" encoding = "UTF-8"?>
<! -- Generated with glade 3.20.0 -->
<Interface>
<Requires lib = "gtk +" version = "3.0"/>
<Object class = "GtkWindow" id = "window">
<Property name = "can_focus"> False </property>
<Signal name = "delete-event" handler = "onDeleteWindow" swapped = "no"/>
<Child>
<Object class = "GtkButton" id = "button">
<Property name = "label" translatable = "yes"> click me </property>
<Property name = "visible"> True </property>
<Property name = "can_focus"> True </property>
<Property name = "receives_default"> True </property>
</Object>
</Child>
</Object>
</Interface>

App. py

#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
Import gi
Import time
Gi. require_version ('gtk ', '3. 0 ')
From gi. repository import Gtk
Class Application (Gtk. Window ):
Def onDeleteWindow (self, * args ):
Gtk. main_quit (* args)
Def clicked (self, button ):
Print ("Hello World! ")
Self. window. set_title ("clicked ")
Self. button. set_label ("clicked ")
Def _ init _ (self ):
Builder = Gtk. Builder ()
Builder. add_from_file ("ui. glade ")
Self. window = builder. get_object ("window ")
Self. window. connect ("delete-event", self. onDeleteWindow)
Self. button = builder. get_object ("button ")
Self. button. connect ("clicked", self. clicked)
Def show_all (self ):
Self. window. show_all ()
App = Application ()
App. show_all ()
Gtk. main ()

Running Effect

Effect after clicking

The red part is the key.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.