歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu下PyGtk的小程序開發之gtkhello.py(圖)

Ubuntu下PyGtk的小程序開發之gtkhello.py(圖)

日期:2017/2/28 17:13:40   编辑:Linux教程

Ubuntu下有趣的漂亮的小程序實在是太多了,真想知道那些天才般的程序員是如何做到的,所以想學習linux下圖形界面程序的開發。
校園網在訪問國外網站時是很要命的,幸好同學有用網通上網的,先去找了一些教程和資料試著編了一個hello world小程序。正如預料的那樣,出錯是難免的!通過dir(gtk)查找函數再加上自己的一點猜測,竟把那個例子改好了,最後明白原來是那些例子是老版本gtk的,現在2.0版本的函數名稱有很多都變了。

gtkhello.py

from gtk import * # importing all the widgets from gtk

window = Window(WINDOW_TOPLEVEL) # create a top level window
window.connect("destroy", main_quit) # quit the event loop on destruction
window.set_border_width(10) # set padding round child widget

button = Button("Hello World") # A button with the "Hello World" label
window.add(button) # add button to window

window.show_all() # Show the window with his widgets
main() # enter the main event loop

Copyright © Linux教程網 All Rights Reserved