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.

%MINIFYHTMLc4d45c48b2cb567af3b101a7a471dfa743%
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()
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 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.

The Secret Role of Karma in Mahabharata

The seeds of Mahabharata were sown long back Duryodhana or Dhritarashtra were born. The story of Kaurvas and Pandavas is only the second half of the cycle of Karma. So what is the first half?

The Real Super Food is free and all around you

Are you looking for some super food that can keep you healthy and strong forever? Do you want to stay free from all illness and health issues?

Latest Music 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.

Chinni Chinni Aasa Chinnadaani Asa – Roja – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Chinni Chinni Aasa Chinnadaani Asa from the 1992 Telugu movie Roja in Western and Indian Notations.
Content Protection by DMCA.com