Development of PyGtk in Ubuntu: Base. py

Source: Internet
Author: User
PyGtk is not difficult. It is similar to Tkinter. On the Internet, when the logic code and view code are combined, PyGtk performs the best job and should be able to learn it later. But there are still doubts about some things. PyGtk2.0 is a collection of Python modules and provides Python interfaces for GTK + 2. X. GTK (GIMPToolkit) is a library used to create a graphical user interface.

PyGtk is not difficult. It is similar to Tkinter. On the Internet, when the logic code and view code are combined, PyGtk performs the best job and should be able to learn it later. But there are still doubts about some things.

PyGtk2.0 is a collection of Python modules and provides Python interfaces for GTK + 2. X.

GTK (GIMP Toolkit) is a library for creating graphical user interfaces, which is fully written in C language.

Base. py

#! /Usr/bin/envpython
#Examplebase. py
ImportPygtk
Pygtk.Require(2.0)
ImportGtk

ClassBase:

Def _ Init __(Self ):
Self. window = gtk.Window(Gtk. WINDOW_TOPLEVEL)
Self. window.Show()

Def Main(Self ):
Gtk.Main()


Print_ Name __

If_ Name __= = "_ main __":
Base =Base()
Base.Main()

Why can I "import gtk? Is gtk a gtk. py file? No, I did not find it.

Comment out"ImportPygtk and pygtk.Require(2.0) "the program can run as usual, that is, pygtk is useless. You can see that the call in the Code only calls gtk. But gtk is written in C language. Why can I directly access gtk without using pygtk in python?

The relationship between pygtk and gtk and their respective organizational structures are unclear.

------------------------------------------------------

I suddenly remembered Eclipse when I went to the canteen to buy a meal. Why don't I use CTRL + CLICK to view the gtk file? So I don't know where it is? It turns out that this trick is not easy to use. It is finally found through the Debug method.

"Import gtk" is actually executing the "C: \ Python25 \ Lib \ site-packages \ gtk-2.0 \ gtk \ __init _. py" file.
In this file, "from gtk import _ gtk" is used to import the _ gtk. pyd file in the gtk folder. The following is an example of "from gtk. _ gtk import *" imported from this. pyd file. Including "Label", "Button", and so on.


"Window" and "WINDOW_TOPLEVEL" in "gtk. Window (gtk. WINDOW_TOPLEVEL)" are all from gdk in gtk. You can view them using "from gtk import gdk" and "dir (gdk.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.