https://github.com/tahairavani/learn-gtk4-with-python
A guide for those who are just starting out learning Gtk for python applications.
https://github.com/tahairavani/learn-gtk4-with-python
gtk gtk4 gui python python3 tutorial
Last synced: 5 months ago
JSON representation
A guide for those who are just starting out learning Gtk for python applications.
- Host: GitHub
- URL: https://github.com/tahairavani/learn-gtk4-with-python
- Owner: tahairavani
- Created: 2025-08-09T10:59:49.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-08-09T12:37:54.000Z (6 months ago)
- Last Synced: 2025-08-09T13:21:12.661Z (6 months ago)
- Topics: gtk, gtk4, gui, python, python3, tutorial
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# how to learn Gtk4 with python ?
hi 👋 To my programmer friends! today let's learn Gtk4 with python for create any application📱
I'm just learning GTK myself, so I'm trying to share anything new I learn about it here.
If you liked it and I was able to help you on your way to learning GTK, I would be happy if you would star the project ⭐
## install Gtk4 for python
you can install Gtk4 for python with pip
first install pycairo with this command :
~~~shell
pip install pycairo
~~~
and next install gtk for python with this command :
~~~shell
pip install PyGObject
~~~
Congratulations, you have successfully installed GTK on your Python. 😍
## use Gtk4 in python
for use gtk version 4 in python and create your helpful application import gtk from gi and utilize this mudle in your apps
### 1. import Gtk
for import gtk you can type this code's
~~~python
import gi
#setup to version 4.0
gi.require_version('Gtk','4.0')
#import Gtk
from gi.repository import Gtk
~~~
### 2. create your first gui app with gtk
create your window with Gtk.ApplicationWindow() object
~~~python
def on_open_application(app):
window = Gtk.ApplicationWindow(application = app) # create window
window.present() # show window
~~~
### 3. create your application and connect to your window and in last step run it !
~~~python
app = Gtk.Application() # create application
app.connect("activate",on_open_application) # connect your application to window
app.run(None) #start your application
~~~
### 4. run your program with python
you succsessful develop your first application
compileted code :
~~~python
import gi
#setup to version 4.0
gi.require_version('Gtk','4.0')
#import Gtk
from gi.repository import Gtk
def on_open_application(app):
window = Gtk.ApplicationWindow(application = app) # create window
window.present() # show window
app = Gtk.Application() # create application
app.connect("activate",on_open_application) # connect your application to window
app.run(None) #start your application
~~~
i write it code on first_app.py in this repository
~~~shell
python your_app.py
~~~