个人工具

“UbuntuHelp:PythonRecipes/GTKBasics”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/PythonRecipes/GTKBasics}} {{Languages|UbuntuHelp:PythonRecipes/GTKBasics}} #title GTK Basics This article is intended to outline some of the basi...)
 
第2行: 第2行:
 
{{Languages|UbuntuHelp:PythonRecipes/GTKBasics}}
 
{{Languages|UbuntuHelp:PythonRecipes/GTKBasics}}
 
#title GTK Basics
 
#title GTK Basics
 
 
This article is intended to outline some of the basic concepts used in GTK.
 
This article is intended to outline some of the basic concepts used in GTK.
 
 
=== Widgets ===
 
=== Widgets ===
 
 
Buttons, labels, scrollbars and even windows are known as ''widgets'' in GTK. Every object you can put into a window is a widget.
 
Buttons, labels, scrollbars and even windows are known as ''widgets'' in GTK. Every object you can put into a window is a widget.
 
 
Widgets have the following things associated with them:
 
Widgets have the following things associated with them:
 
 
* '''Properties''' - The properties of a widget, such as what size it is, how many characters it will accept and so on. Properties can be read only or read/write.
 
* '''Properties''' - The properties of a widget, such as what size it is, how many characters it will accept and so on. Properties can be read only or read/write.
 
* '''Style Properties''' - Properties related to how the widget looks, such as its colour and border style.
 
* '''Style Properties''' - Properties related to how the widget looks, such as its colour and border style.
 
* '''Signals''' - Signals which are emitted when an event occurs involving the widget (e.g. clicking the widget). You can use signals to run functions when such an event occurs.
 
* '''Signals''' - Signals which are emitted when an event occurs involving the widget (e.g. clicking the widget). You can use signals to run functions when such an event occurs.
 
* '''Methods''' - Functions which can be called to manipulate the widget and pass or receive information from it. For example, you might call the get_text() method to get the text currently contained by the widget.
 
* '''Methods''' - Functions which can be called to manipulate the widget and pass or receive information from it. For example, you might call the get_text() method to get the text currently contained by the widget.
 
 
=== Containers ===
 
=== Containers ===
 
 
Certain widgets are able to contain other widgets. For example, a Window widget can contain one widget, which can itself contain several more widgets, all of which may be able to contain widgets too. You can think of the widgets in a GTK project as being organised as a tree.
 
Certain widgets are able to contain other widgets. For example, a Window widget can contain one widget, which can itself contain several more widgets, all of which may be able to contain widgets too. You can think of the widgets in a GTK project as being organised as a tree.
 
 
Containers are useful for arranging widgets in a window. If the parent widget of other widgets is hidden, then those widgets will be hidden too.
 
Containers are useful for arranging widgets in a window. If the parent widget of other widgets is hidden, then those widgets will be hidden too.
 
 
Below is a list of useful containers:
 
Below is a list of useful containers:
 
 
* '''Window''' - This is a normal window, the kind that you see everywhere on your desktop. Windows can only directly contain one widget themselves, so you'll normally want to put another type of container in your window first.
 
* '''Window''' - This is a normal window, the kind that you see everywhere on your desktop. Windows can only directly contain one widget themselves, so you'll normally want to put another type of container in your window first.
 
* '''VBox''' - A container with a column of invisible 'slots' which widgets can be put into. Useful for organising things vertically.
 
* '''VBox''' - A container with a column of invisible 'slots' which widgets can be put into. Useful for organising things vertically.
 
* '''HBox''' - Similar to VBox, but horizontal instead of vertical.
 
* '''HBox''' - Similar to VBox, but horizontal instead of vertical.
 
 
=== Events and Signals ===
 
=== Events and Signals ===
 
 
Widgets can be made to perform functions when an ''event'' occurs. An example of an event is a button being clicked. When the event occurs, the widget sends out a ''signal'', in this case the ''clicked'' signal. You can find a list of valid signals in the GTK documentation.
 
Widgets can be made to perform functions when an ''event'' occurs. An example of an event is a button being clicked. When the event occurs, the widget sends out a ''signal'', in this case the ''clicked'' signal. You can find a list of valid signals in the GTK documentation.
 
 
These signals can be received by signal handling functions which you have defined. You can ''connect'' functions in your code to certain signals, so that when the signal is received your function is run. For example, when the button is clicked, we might want to run a function which pops up a message.
 
These signals can be received by signal handling functions which you have defined. You can ''connect'' functions in your code to certain signals, so that when the signal is received your function is run. For example, when the button is clicked, we might want to run a function which pops up a message.
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 21:10的版本

  1. title GTK Basics

This article is intended to outline some of the basic concepts used in GTK.

Widgets

Buttons, labels, scrollbars and even windows are known as widgets in GTK. Every object you can put into a window is a widget. Widgets have the following things associated with them:

  • Properties - The properties of a widget, such as what size it is, how many characters it will accept and so on. Properties can be read only or read/write.
  • Style Properties - Properties related to how the widget looks, such as its colour and border style.
  • Signals - Signals which are emitted when an event occurs involving the widget (e.g. clicking the widget). You can use signals to run functions when such an event occurs.
  • Methods - Functions which can be called to manipulate the widget and pass or receive information from it. For example, you might call the get_text() method to get the text currently contained by the widget.

Containers

Certain widgets are able to contain other widgets. For example, a Window widget can contain one widget, which can itself contain several more widgets, all of which may be able to contain widgets too. You can think of the widgets in a GTK project as being organised as a tree. Containers are useful for arranging widgets in a window. If the parent widget of other widgets is hidden, then those widgets will be hidden too. Below is a list of useful containers:

  • Window - This is a normal window, the kind that you see everywhere on your desktop. Windows can only directly contain one widget themselves, so you'll normally want to put another type of container in your window first.
  • VBox - A container with a column of invisible 'slots' which widgets can be put into. Useful for organising things vertically.
  • HBox - Similar to VBox, but horizontal instead of vertical.

Events and Signals

Widgets can be made to perform functions when an event occurs. An example of an event is a button being clicked. When the event occurs, the widget sends out a signal, in this case the clicked signal. You can find a list of valid signals in the GTK documentation. These signals can be received by signal handling functions which you have defined. You can connect functions in your code to certain signals, so that when the signal is received your function is run. For example, when the button is clicked, we might want to run a function which pops up a message.