這是一個extreeemely模糊的問題.. 但在這裏,我們去..我會跳過大部分傳統的模塊(如Tk的或wxPython的,但他們可以爲你工作)。
我通常呈現Pyglet選項,任何人在GUI開發或任何圖形聰明有趣..
這裏是一個簡短的拖N - 下降例如:
#!/usr/bin/python
import pyglet
from time import time, sleep
class Window(pyglet.window.Window):
def __init__(self, refreshrate):
super(Window, self).__init__(vsync = False)
self.frames = 0
self.framerate = pyglet.text.Label(text='Unknown', font_name='Verdana', font_size=8, x=10, y=10, color=(255,255,255,255))
self.last = time()
self.alive = 1
self.refreshrate = refreshrate
self.click = None
self.drag = False
def on_draw(self):
self.render()
def on_mouse_press(self, x, y, button, modifiers):
self.click = x,y
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
if self.click:
self.drag = True
print 'Drag offset:',(dx,dy)
def on_mouse_release(self, x, y, button, modifiers):
if not self.drag and self.click:
print 'You clicked here', self.click, 'Relese point:',(x,y)
else:
print 'You draged from', self.click, 'to:',(x,y)
self.click = None
self.drag = False
def render(self):
self.clear()
if time() - self.last >= 1:
self.framerate.text = str(self.frames)
self.frames = 0
self.last = time()
else:
self.frames += 1
self.framerate.draw()
self.flip()
def on_close(self):
self.alive = 0
def run(self):
while self.alive:
self.render()
# ----> Note: <----
# Without self.dispatc_events() the screen will freeze
# due to the fact that i don't call pyglet.app.run(),
# because i like to have the control when and what locks
# the application, since pyglet.app.run() is a locking call.
event = self.dispatch_events()
sleep(1.0/self.refreshrate)
win = Window(23) # set the fps
win.run()
在這裏,您將不得不創建自己的對象(文本框,滑塊等),但你將有完整控制他們。
我已經構建了幾個(8-13)大型GUI應用程序,如果您不想使用磚查看按鈕和通用顏色格式,這是最乾淨的方法。
而且,看到這個線程和多對GUI的討論,什麼是最好的模塊等:
而對於Pyglet: