如果您願意使用Tkinter,下面是一個使用畫布小部件的簡短示例。
import Tkinter as tk
class Example(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
canvas = tk.Canvas(self, width=800, height=500)
canvas.pack(side="top", fill="both", expand=True)
for i in range(0, 800, 40):
i+= 40
fill = "yellow" if (i/40) % 2 == 0 else "green"
canvas.create_rectangle(i, 0, i+20, 500, fill=fill, outline="")
canvas_id = canvas.create_text(10, 10, anchor="nw")
canvas.itemconfig(canvas_id, text="this is the text "*300, width=780)
canvas.itemconfig(canvas_id, font=("courier", 12))
canvas.insert(canvas_id, 12, "new ")
if __name__ == "__main__":
root = tk.Tk()
Example(root).pack(side="top", fill="both", expand=True)
root.mainloop()
這裏是什麼樣子:
![screenshot of working example](https://i.stack.imgur.com/8RdZf.png)
添加滾動就留給讀者自己練習。
我相信gtk3可以做到這一點,也許gtk2。您可能正在尋找pygame或pyglet的更多內容 – korylprince
我曾考慮過使用pyglet,但pyglet的GUI工具包幾乎不存在或在過去5年內未更新。我會檢查gtk,謝謝:) – Josh