Python GUI Development with GTK+ 3 - Tutorial 1 - Simple Window

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

THIS is the information I've been hunting for for the last 4 hours. Thank you for posting.

brianburch
Автор

FOR THOSE OF YOU WANTING TO INSTALL GTK+ 3:

INSTALL USING PIP:
You must first install PyOpenGL libraries to support the GTK applications. These are often but not always necessary.

FROM YOUR CONSOLE:
pip install PyOpenGL PyOpenGL-accelerate OpenGLContext

FOR WINDOWS USERS:
You must download and install the MSYS2 shell. The installer is linked on the page. Open the MSYS2 shell and use the pacman package handler to download and install gtk package, python3 gobject libraries and the glade GUI builder application which supports python GTK applications. Note that you are installing these into your system from source.
FROM CMD, MSYS2 shell:
> pacman -S mingw-w64-x86_64-gtk3
> pacman -S mingw-w64-x86_64-glade
> pacman -S


FOR LINUX USERS:
Using your default package manager (apt, dnf, yum, pacman, etc) and install the following packages. (I use apt but substitute your own package manager syntax as needed)
> sudo apt-get install libgtk-3-0 libgtk-3-bin libgtk-3-common libgtk-3-dev python3-gobject glade
Some distros also may require the gir1.2-gtk package, mine did not.
Package names may vary as versions advance, so bear all this with a grain of salt.

FOR ANYONE WHO USES PYCHARM:
It is important to check what version of python your pip is installing packages for and what interpreter pycharm is using.
Example: If you are using pip to install packages for python 3.6, but Pycharm is using python 3.5 interpreter, then you will lose intellisense, inspection, and code completion in pycharm.

Go to Pycharm Settings > Project Settings > Interpreter > (Set your interpreter to the version of python which all of your gtk dependencies are installed for ie: Python 3.6)
Create your import statement

```
#!/usr/bin/env python3.6
import gi
gi.require_version('Gtk', '3.0)
from gi.repository import Gtk
```
NOW! You will see Gtk as an unresolved package. Place your Carat/Cursor on Gtk and
<ALT> + <ENTER>
Select "Generate Stubs for Binary Module"
Wait for the stubs to process and pycharm will once again support code completion. Note, this will take some time. GOOD LUCK! :D

Oh...and Here's a downvote from me to thenewboston for failing to provide ANY installation instructions for anybody. This was not an easy install, even for experienced python devs. You should have known better. >_<

TheDevilsStockBroker
Автор

Wow, I started watching your videos when I was really young and trying to learn Java. And here I am now, several years later still watching. I didn't even know it was a video by you at first, until I heard your voice. And then I was like: oh this guy is good, I trust him. Thanks so much for staying relevant

soulelemanator
Автор

Great timing! I've been wanting to learn gtk / qt. This'll ease reading documentation while eating lunch!

XavierBergeron
Автор

for Windows...
2. download the latest installer (210MB)
3. during installation, tick only the base & Gtk3
4. inside pycharm, choose python 2.x for ur project interpreter
5. inside your code, u've to write these lines 1st:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

izanorshahril
Автор

Things changed a bit since this video has been made. In case you get the following warning on the console:
PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
you have to change the way you import the library into something like this:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
That is, you first import the GObject Introspection module, then tell it which version of the GTK+ library you want to use (3.0 in this case), and only then you import the `Gtk` module.

bonbonpony
Автор

THIS CODE WILL NOT RUN, EXCEPT ON A LINUX OS. HERE'S HOW TO MAKE THIS WORK ON ANY WINDOWS OS (better than Vista):


2.) Before installing that program, note that THIS MODULE ONLY WORKS ON Python 3.4 and LOWER. Download an older copy of Python, 3.4 and lower, and have that loaded onto your machine.

3.) While installing this, click on your 3.4 Python or lower, and then when it asks you what packages you want to install, just click on anything you think might be useful, including Gtk 3.

4.) Load up PyCharm, and make sure your project is set to compile with the specific Python.exe that you just loaded GObject onto. Furthermore, on Windows (and MacOS, I believe), your code must be amended to:

Begin Code
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk


Window = Gtk.Window()
Window.connect("delete-event", Gtk.main_quit)

Window.show_all()
Gtk.main()
END CODE

Notice that the header portion where we import the module must specify the import gi first, then specify the version. You must specify Gtk to be 3.0 on Windows machines, because reasons.

5.) That's not enough, the final step is that on PyCharm you MUST "altl"+"enter" the word Gtk, and you must choose "Generate stubs for binary module". You'll notice that it has a red line under it, which is apparently because you still need to compile the module even after everything you've done, because reasons. It will likely take several minutes (look at the progress on the bottom right corner of the screen).

6.) You may now run your program in Windows.

GoldPhoenix
Автор

Hey Bucky, Your videos are great. One suggestion that I have for you is that on the first video show the end product so that the viewer knows what they are working to. Just a thought. Again, you are great!

rockon-wbfqlkjqhsydic
Автор

man, I downloades it all on the youtube-dl, but, I return here just to mark 'Like', 'cuz u deserve man, thks! (Y)

alvarorodrigo
Автор

To me, you are great. And now you use Ubuntu, awesome

Aleinux
Автор

what's the difference between Tkinter and GTK ??

mehdimahdi
Автор

Hello, I got a problem with Gtk in PyCharm. The PyCharm autocomplete seem not work for Gtk. Should I forgot setting something? Thanks for your help.

mingchi
Автор

Yes! Going bookmark and start this later.

TeamGenerationFTW
Автор

pygobject is not installing in pycharm please help

movieanytime
Автор

Bucky, I love your channel more than anything, but please stick too one tutorial and finish it :'(

wyattlowery
Автор

Can you please show us how to install GTK, I am not really sure how to do it. I tried, but my Python is installed in kind of a weird location, which it did by default on Windows 10, and it keeps telling me it cant find my python installation. But with hidden folders I can't specify the location with my installer.

NickPangburn
Автор

I ran into an issue when trying to install it. It says error: non zero exit code and showed a bunch of things. Amongst the most noteworthy being: No package 'gobject-introspection-1.0' found. Help!?

scalemath
Автор

How do I install pyGObject if I am not using pycharm.

AryanKumar-vwtu
Автор

I learned with you javafx, now I have to learn python gtk :O

ismendoza
Автор

Missing some packages to follow your tutorial using RHEL 9.2. Help please

dthurm