如果您愿意使用 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()
这是它的样子:
添加滚动作为练习留给读者。