Grafik Kullanıcı Arayüzü SSS

Genel GKA Soruları

What platform-independent GUI toolkits exist for Python?

Depending on what platform(s) you are aiming at, there are several. Some of them haven’t been ported to Python 3 yet. At least Tkinter and Qt are known to be Python 3-compatible.

Tkinter

Standard builds of Python include an object-oriented interface to the Tcl/Tk widget set, called tkinter. This is probably the easiest to install (since it comes included with most binary distributions of Python) and use. For more info about Tk, including pointers to the source, see the Tcl/Tk home page. Tcl/Tk is fully portable to the Mac OS X, Windows, and Unix platforms.

wxWidgets

wxWidgets (https://www.wxwidgets.org) is a free, portable GUI class library written in C++ that provides a native look and feel on a number of platforms, with Windows, Mac OS X, GTK, X11, all listed as current stable targets. Language bindings are available for a number of languages including Python, Perl, Ruby, etc.

wxPython is the Python binding for wxwidgets. While it often lags slightly behind the official wxWidgets releases, it also offers a number of features via pure Python extensions that are not available in other language bindings. There is an active wxPython user and developer community.

Both wxWidgets and wxPython are free, open source, software with permissive licences that allow their use in commercial products as well as in freeware or shareware.

Qt

There are bindings available for the Qt toolkit (using either PyQt or PySide) and for KDE (PyKDE4). PyQt is currently more mature than PySide, but you must buy a PyQt license from Riverbank Computing if you want to write proprietary applications. PySide is free for all applications.

Qt 4.5 upwards is licensed under the LGPL license; also, commercial licenses are available from The Qt Company.

Gtk+

The GObject introspection bindings for Python allow you to write GTK+ 3 applications. There is also a Python GTK+ 3 Tutorial.

The older PyGtk bindings for the Gtk+ 2 toolkit have been implemented by James Henstridge; see <http://www.pygtk.org>.

Kivy

Kivy is a cross-platform GUI library supporting both desktop operating systems (Windows, macOS, Linux) and mobile devices (Android, iOS). It is written in Python and Cython, and can use a range of windowing backends.

Kivy is free and open source software distributed under the MIT license.

FLTK

Python bindings for the FLTK toolkit, a simple yet powerful and mature cross-platform windowing system, are available from the PyFLTK project.

OpenGL

For OpenGL bindings, see PyOpenGL.

What platform-specific GUI toolkits exist for Python?

By installing the PyObjc Objective-C bridge, Python programs can use Mac OS X’s Cocoa libraries.

Pythonwin by Mark Hammond includes an interface to the Microsoft Foundation Classes and a Python programming environment that’s written mostly in Python using the MFC classes.

Tkinter soruları

Tkinter uygulamalarını nasıl dondurabilirim?

Dondurma işlemi, tek başına bağımsız uygulamalar oluşturmak için bir araçtır. Tkinter uygulamalarını dondururken, uygulama hala Tcl ve Tk kütüphanelerine ihtiyaç duyacağından, uygulamalar gerçekten bağımsız olmayacaktır.

Çözümlerden biri, uygulamayı Tcl ve Tk kütüphaneleri ile birlikte göndermek ve çalışma zamanında TCL_LIBRARY ve TK_LIBRARY ortam değişkenlerini kullanarak onlara işaret etmektir.

To get truly stand-alone applications, the Tcl scripts that form the library have to be integrated into the application as well. One tool supporting that is SAM (stand-alone modules), which is part of the Tix distribution (http://tix.sourceforge.net/).

SAM etkinken Tix oluşturun, Python’un Modules/tkappinit.c içindeki Tclsam_init() vb. için uygun çağrıyı yapın ve libtclsam ve libtksam ile bağlantı kurun (Tix kütüphanelerini da dahil edebilirsiniz) ).

G/Ç’yi beklerken Tk olaylarını işleyebilir miyim?

Windows dışındaki platformlarda, evet ve iş parçacığına bile ihtiyacınız yok! Ancak G/Ç kodunuzu tekrardan yapılandırmanız gerekecek. Tk, Xt’nin XtAddInput() çağrısına eşdeğerdir; bu, bir dosya tanıtıcısında G/Ç mümkün olduğunda Tk ana döngüsünden çağrılacak bir geri arama işlevini kaydetmenize olanak tanır. Bkz. File Handlers

Tkinter’da çalışmak için anahtar bağlamalarını alamıyorum: neden?

Sıkça duyulan bir şikayet, bind() yöntemiyle olaylara bağlanan işleyicilerin uygun tuşa basıldığında bile işlenmemesidir.

En yaygın neden, bağlamanın uygulandığı pencere öğesinin “klavye odağına” sahip olmamasıdır. Focus komutu için Tk dokümantasyonuna bakın. Genellikle Wigdet’lara tıklanılarak klavye odağı verilir (ancak etiketler için değil; odak alma seçeneğine bakın).