-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
73 lines (53 loc) · 2.73 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# A simple application of the xcanvas module
# Intended for applications with a single Canvas window
# The name of this Canvas is simply: canvas
# (but you can change it to any name you like)
# Once you load this module, you can use this canvas object to draw your figures ...
from xcanvas import *
try:
rootWindow
except NameError:
rootWindow = tk.Tk()
# This is where we create our canvas instance
# The name canvas referes to it when you import this module
canvas = XCanvas(rootWindow, width=1000, height=800, bg="white")
def show_canvas():
tk.mainloop()
#-----------------------------------------------------------------------
def test1():
id = canvas.create_rectangle(100, 120, 400, 230, width=2, outline="blue", fill="yellow")
print("Rectangle 1 id:", id)
canvas.create_text(200, 180, text="Rectangle 1", fill="maroon", font=("Consolas", 15, "bold"))
id = canvas.create_rectangle(400, 320, 600, 530, width=5, outline="darkblue", fill="cyan")
print("Rectangle 2 id:", id)
canvas.create_text(500, 470, text="Rectangle 2", fill="Darkblue", font=("Times New Roman", 18, "bold"))
id = canvas.create_line(200, 50, 500, 430, width=3, fill="DarkOrange")
print("Line 1 id:", id)
id = canvas.create_line(200, 60, 500, 440, width=3, fill="DarkOrange", dash=(2,3))
print("Line 2 id:", id)
print("Canvas Scroll Region:", canvas["scrollregion"])
id = canvas.create_oval(100, 420, 300, 620, width=3, outline="darkgreen", fill="cornsilk")
print("Circle id:", id)
canvas.create_text(200, 520, text="Circle", fill="maroon", font=("Consolas", 15, "bold"))
id = canvas.create_oval(450, 120, 650, 240, width=5, outline="goldenrod4", fill="tan")
print("Ellipse id:", id)
canvas.create_text(550, 180, text="Ellipse", fill="white", font=("Copperplate Gothic Bold", 21, "bold"))
show_canvas()
def test2():
# Hide the main canvas
canvas.hide()
# We can actually create multiple canvas instances !
rootwin1 = tk.Tk()
canvas1 = XCanvas(rootwin1, width=1000, height=800, bg="white")
canvas1.create_rectangle(100, 120, 400, 230, width=2, outline="blue", fill="yellow")
canvas1.create_rectangle(400, 320, 600, 530, width=2, outline="red", fill="cyan")
canvas1.create_line(200, 50, 500, 430, width=3, fill="blue")
rootwin2 = tk.Tk()
canvas2 = XCanvas(rootwin2, width=1000, height=800, bg="gray90")
canvas2.create_rectangle(100, 120, 400, 230, width=2, outline="blue", fill="orange")
canvas2.create_rectangle(400, 320, 600, 530, width=2, outline="red", fill="yellow")
canvas2.create_line(200, 50, 500, 430, width=3, fill="red")
show_canvas()
if __name__ == "__main__":
test1()
#test2()