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.

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
Code language: Python (python)

You can initialize and launch the application as follows:

myapp = MyGuiApp("MyGUI.glade") myapp.launch()
Code language: JavaScript (javascript)
Content Protection by DMCA.com

Download HitXP Mobile App

Get it on Google Play
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

How does GOD helps us?

Do prayers really help? Do miracles happen when we are in trouble? Does God really help us in times of need? Are prayers enough to save us during bad times? How should we face problems?

Sanskrit poem on Ramayana – read in reverse becomes Mahabharata!

A Sanskrit poem about Ramayana when read in reverse direction becomes a poem on Mahabharata!

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.

Latest Music Notations

Oo Antava Mava – Pushpa – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Oo Antava Mava from the 2022 Telugu movie Pushpa in Western and Indian Notations.

Kaa Chalige Bangalore (Tiningaa Miningaa Tishaaaa) – Salaga – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Tiningaa Miningaa Tishaaaa (Kaa Chali Ge) from the 2022 Kannada movie Salaga in Western and Indian Notations.

Title Track BGM – Irul – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Title Track BGM from the 2021 Malayalam movie Irul in Western and Indian Notations.

Ninnukori Varnam – Agni Natchathiram – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Ninnukori Varnam from the 1988 Tamil movie Agni Natchathiram in Western and Indian Notations.
Content Protection by DMCA.com