Home Code Python Class Template example for GTK+ GUI Application built using Glade

Python Class Template example for GTK+ GUI Application built using Glade

This article contains a bare bone Python Class Template, an example class or a sample class to load GUI built using Glade. The class can launch the GUI application. You can add Python event code functions to handle GTK+ GUI signals of UI objects like GTKApplicationWindow, GTJKListbox, GTKButton, GTKLabel, etc.

This class assumes that you have built your GUI interface using Glade, and the Glade file name is “MyGUI.glade”. This class also assumes that you have linked UI events or signals to Python function names using the signals tab of each GUI object in Glade. In the signals tab of Glade you can enter names of Python functions for all GUI events that object can handle like key events, mouse events and other user action events.

Use the below class as a base template for your GUI application and build your complete GUI application quickly. All thanks to Glade and Python – GUI programming has never been so easy on Linux or Ubuntu systems.

%MINIFYHTML19b390a0ac6ef9786f5e55c2bad3963342%
import gi #make sure you have latest GTK version gi.require_version('Gtk', '3.0') from gi.repository import Gtk class MyGUIApp: def __init__(self,glade_file): #Initialize the GTK Builder self.builder = Gtk.Builder() #Load GUI from the Glade File self.builder.add_from_file(glade_file) #Link all GUI events specified in Glade to corresponding functions in this class self.builder.connect_signals(self) def launch(self): #assuming your main window in Glade has ID winMain window = self.builder.get_object("winMain") window.show_all() window.maximize() Gtk.main() #make sure you have set destroy signal to "onDestroy" in Glade for "winMain" #else this function will not be called on close event of main application window def onDestroy(self, *args): #quit the application on closing of main application window Gtk.main_quit() #Write additional functions below to handle other events or signals #The function names can be linked to specific GUI events in Glade itself in the signals tab of each GUI object in Glade

You can initialize and launch the application as follows:

myapp = MyGuiApp("MyGUI.glade") myapp.launch()

Download HitXP Mobile App on Google Play

Get it on Google Play
Content Protection by DMCA.com
Gurudevhttps://www.hitxp.com
Gurudev is the developer of Gurunudi AI Platform. This is his official website where he pens his thoughts on a wide range of topics, answers queries, shares resources and tools developed by him.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

FacebookLike
InstagramFollow
PinterestFollow
RSS FeedSubscribe
Sound CloudFollow
TwitterFollow
YoutubeSubscribe

Latest Articles

The difference between Itihasa and Puranas

Documentation of ancient Indian history and the historical events of Indian civilization in the form of Itihasa and Puranas - Ramayana and Mahabharata.

Online Education should be interactive and innovative – Fun to Learn

For online education to succeed for smaller classses - it should be as interesting as cartoons. Online education cant succeed unless it is more interesting, interactive and innovative than offline schooling.

The Complete List of Dhatus – Sanskrit Root Words and their English meaning

A complete list of all dhatus (root words or verb roots) in Sanskrit dictionary and their meanings with corresponding IPA transliteration.

Sanskrit Lesson 4 – Word Creation Magic using Dhatus

Learn how easy it is to create new words in Sanskrit using root words called Dhatus. This simple process of Sanskrit grammar powers the entire language.

Latest Music Notations

So Gaya Ye Jahan – Tezaab – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song So Gaya Ye Jahan from the 1988 Hindi movie Tezaab in Western and Indian Notations.

Background Theme (BGM) – Mouna Ragam – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Background Theme (BGM) from the 1986 Tamil movie Mouna Ragam in Western and Indian Notations.

Dil Kya Kare Jab Kisi Se – Julie – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Dil Kya Kare Jab Kisi Se from the 1975 Hindi movie Julie in Western and Indian Notations.

Albela Sajan Aayo Re – Hum Dil De Chuke Sanam – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Albela Sajan Aayo Re from the 1999 Hindi movie Hum Dil De Chuke Sanam in Western and Indian Notations.

Download HitXP Mobile App on Google Play

Get it on Google Play
Content Protection by DMCA.com