预发布版本
2.0版本运用了tkinter库,新增了控制面板
为了这个,我还特地去学了tkinter库...
测试版本,只有三角形和正方形,增加了清除界面和终止程序功能,想退出直接按结束程序键,不用再按x了。
代码如下👇
from turtle import *
import tkinter as tk
import sys
def triangle():
clearscreen()
for i in range(3):
fd(200)
lt(120)
def rectangle():
clearscreen()
for i in range(4):
fd(200)
lt(90)
def clearWindow():
clearscreen()
def exitCommand():
sys.exit()
window=tk.Tk()
window.title('paintControlPanel_v2.0') # 窗口标题
window.geometry('500x500') #窗口大小
button = tk.Button(text="三角形",font=("Arial",25),fg="black",command=triangle)
button.place(x=0,y=100)
button = tk.Button(text="正方形",font=("Arial",25),fg="black",command=rectangle)
button.place(x=0,y=200)
button = tk.Button(text="清除画板",font=("Arial",25),fg="black",command=clearWindow)
button.place(x=0,y=300)
button = tk.Button(text="结束程序",font=("Arial",25),fg="black",command=exitCommand)
button.place(x=200,y=300)
tk.Label(window, text="画图软件控制面板 v2.0 beta1", font='Consolas 15').pack()
window.mainloop()
如果运行不了,应该是没有sys库,重新装一下python就行了。
注意!!!此程序仅在python 3.x上运行!!!python 2.x会报错!!!