Python 【GUI实例】
1 import turtle as t 2 3 #八卦 4 def YY(): 5 t.pencolor("black") 6 t.pensize(5) 7 8 t.circle(100,450) 9 t.circle(50,180) 10 t.circle(-50,180) 11 t.right(90) 12 t.penup() 13 t.forward(40) 14 t.left(90) 15 t.pendown() 16 t.circle(-10) 17 t.right(90) 18 t.penup() 19 t.forward(100) 20 t.left(90) 21 t.pendown() 22 t.circle(-10) 23 24 #八边形 25 def eight(long=120): 26 t.penup() 27 t.goto(-60,-120) 28 t.pendown() 29 for i in range(8): 30 t.forward(long) 31 t.left(45) 32 33 34 35 #单根线 36 def Line(a,x,y): 37 t.pen(pencolor="black",pensize=5) 38 if(a==1): 39 t.penup() 40 t.goto(x,y) 41 t.pendown() 42 t.forward(60) 43 else: 44 t.penup() 45 t.goto(x,y) 46 t.pendown() 47 t.forward(25) 48 t.penup() 49 t.forward(10) 50 t.pendown() 51 t.forward(25) 52 53 54 55 def main(): 56 57 eight(120) 58 Line(1,-30,150) 59 Line(1,-30,140) 60 Line(1,-30,130) 61 62 63 64 main() 65
1 # coding:utf-8 2 import turtle as t 3 4 t.title("小猪佩奇") 5 t.screensize(400, 300, "white") 6 t.pensize(4) # 设置画笔的大小 7 t.colormode(255) # 设置GBK颜色范围为0-255 8 t.color((255,155,192),"pink") # 设置画笔颜色和填充颜色(pink) 9 t.setup(840,500) # 设置主窗口的大小为840*500 10 t.speed(10) # 设置画笔速度为10 11 #鼻子 12 t.pu() # 提笔 13 t.goto(-100,100) # 画笔前往坐标(-100,100) 14 t.pd() # 下笔 15 t.seth(-30) # 笔的角度为-30° 16 t.begin_fill() # 外形填充的开始标志 17 a=0.4 18 for i in range(120): 19 if 0<=i<30 or 60<=i<90: 20 a=a+0.08 21 t.lt(3) #向左转3度 22 t.fd(a) #向前走a的步长 23 else: 24 a=a-0.08 25 t.lt(3) 26 t.fd(a) 27 t.end_fill() # 依据轮廓填充 28 t.pu() # 提笔 29 t.seth(90) # 笔的角度为90度 30 t.fd(25) # 向前移动25 31 t.seth(0) # 转换画笔的角度为0 32 t.fd(10) 33 t.pd() 34 t.pencolor(255,155,192) # 设置画笔颜色 35 t.seth(10) 36 t.begin_fill() 37 t.circle(5) # 画一个半径为5的圆 38 t.color(160,82,45) # 设置画笔和填充颜色 39 t.end_fill() 40 t.pu() 41 t.seth(0) 42 t.fd(20) 43 t.pd() 44 t.pencolor(255,155,192) 45 t.seth(10) 46 t.begin_fill() 47 t.circle(5) 48 t.color(160,82,45) 49 t.end_fill() 50 #头 51 t.color((255,155,192),"pink") 52 t.pu() 53 t.seth(90) 54 t.fd(41) 55 t.seth(0) 56 t.fd(0) 57 t.pd() 58 t.begin_fill() 59 t.seth(180) 60 t.circle(300,-30) # 顺时针画一个半径为300,圆心角为30°的园 61 t.circle(100,-60) 62 t.circle(80,-100) 63 t.circle(150,-20) 64 t.circle(60,-95) 65 t.seth(161) 66 t.circle(-300,15) 67 t.pu() 68 t.goto(-100,100) 69 t.pd() 70 t.seth(-30) 71 a=0.4 72 for i in range(60): 73 if 0<=i<30 or 60<=i<90: 74 a=a+0.08 75 t.lt(3) #向左转3度 76 t.fd(a) #向前走a的步长 77 else: 78 a=a-0.08 79 t.lt(3) 80 t.fd(a) 81 t.end_fill() 82 #耳朵 83 t.color((255,155,192),"pink") 84 t.pu() 85 t.seth(90) 86 t.fd(-7) 87 t.seth(0) 88 t.fd(70) 89 t.pd() 90 t.begin_fill() 91 t.seth(100) 92 t.circle(-50,50) 93 t.circle(-10,120) 94 t.circle(-50,54) 95 t.end_fill() 96 t.pu() 97 t.seth(90) 98 t.fd(-12) 99 t.seth(0) 100 t.fd(30) 101 t.pd() 102 t.begin_fill() 103 t.seth(100) 104 t.circle(-50,50) 105 t.circle(-10,120) 106 t.circle(-50,56) 107 t.end_fill() 108 #眼睛 109 t.color((255,155,192),"white") 110 t.pu() 111 t.seth(90) 112 t.fd(-20) 113 t.seth(0) 114 t.fd(-95) 115 t.pd() 116 t.begin_fill() 117 t.circle(15) 118 t.end_fill() 119 t.color("black") 120 t.pu() 121 t.seth(90) 122 t.fd(12) 123 t.seth(0) 124 t.fd(-3) 125 t.pd() 126 t.begin_fill() 127 t.circle(3) 128 t.end_fill() 129 t.color((255,155,192),"white") 130 t.pu() 131 t.seth(90) 132 t.fd(-25) 133 t.seth(0) 134 t.fd(40) 135 t.pd() 136 t.begin_fill() 137 t.circle(15) 138 t.end_fill() 139 t.color("black") 140 t.pu() 141 t.seth(90) 142 t.fd(12) 143 t.seth(0) 144 t.fd(-3) 145 t.pd() 146 t.begin_fill() 147 t.circle(3) 148 t.end_fill() 149 #腮 150 t.color((255,155,192)) 151 t.pu() 152 t.seth(90) 153 t.fd(-95) 154 t.seth(0) 155 t.fd(65) 156 t.pd() 157 t.begin_fill() 158 t.circle(30) 159 t.end_fill() 160 #嘴 161 t.color(239,69,19) 162 t.pu() 163 t.seth(90) 164 t.fd(15) 165 t.seth(0) 166 t.fd(-100) 167 t.pd() 168 t.seth(-80) 169 t.circle(30,40) 170 t.circle(40,80) 171 #身体 172 t.color("red",(255,99,71)) 173 t.pu() 174 t.seth(90) 175 t.fd(-20) 176 t.seth(0) 177 t.fd(-78) 178 t.pd() 179 t.begin_fill() 180 t.seth(-130) 181 t.circle(100,10) 182 t.circle(300,30) 183 t.seth(0) 184 t.fd(230) 185 t.seth(90) 186 t.circle(300,30) 187 t.circle(100,3) 188 t.color((255,155,192),(255,100,100)) 189 t.seth(-135) 190 t.circle(-80,63) 191 t.circle(-150,24) 192 t.end_fill() 193 #手 194 t.color((255,155,192)) 195 t.pu() 196 t.seth(90) 197 t.fd(-40) 198 t.seth(0) 199 t.fd(-27) 200 t.pd() 201 t.seth(-160) 202 t.circle(300,15) 203 t.pu() 204 t.seth(90) 205 t.fd(15) 206 t.seth(0) 207 t.fd(0) 208 t.pd() 209 t.seth(-10) 210 t.circle(-20,90) 211 t.pu() 212 t.seth(90) 213 t.fd(30) 214 t.seth(0) 215 t.fd(237) 216 t.pd() 217 t.seth(-20) 218 t.circle(-300,15) 219 t.pu() 220 t.seth(90) 221 t.fd(20) 222 t.seth(0) 223 t.fd(0) 224 t.pd() 225 t.seth(-170) 226 t.circle(20,90) 227 #脚 228 t.pensize(10) 229 t.color((240,128,128)) 230 t.pu() 231 t.seth(90) 232 t.fd(-75) 233 t.seth(0) 234 t.fd(-180) 235 t.pd() 236 t.seth(-90) 237 t.fd(40) 238 t.seth(-180) 239 t.color("black") 240 t.pensize(15) 241 t.fd(20) 242 t.pensize(10) 243 t.color((240,128,128)) 244 t.pu() 245 t.seth(90) 246 t.fd(40) 247 t.seth(0) 248 t.fd(90) 249 t.pd() 250 t.seth(-90) 251 t.fd(40) 252 t.seth(-180) 253 t.color("black") 254 t.pensize(15) 255 t.fd(20) 256 #尾巴 257 t.pensize(4) 258 t.color((255,155,192)) 259 t.pu() 260 t.seth(90) 261 t.fd(70) 262 t.seth(0) 263 t.fd(95) 264 t.pd() 265 t.seth(0) 266 t.circle(70,20) 267 t.circle(10,330) 268 t.circle(70,30) 269 t.done()
1 from tkinter import * 2 from tkinter.messagebox import * 3 4 class LoginPage(Frame): 5 def __init__(self): 6 super().__init__() 7 self.username = StringVar() 8 self.password = StringVar() 9 self.pack() 10 self.createForm() 11 12 def createForm(self): 13 Label(self).grid(row=0, stick=W, pady=10) 14 Label(self, text = '账户: ').grid(row=1, stick=W, pady=10) 15 Entry(self, textvariable=self.username).grid(row=1, column=1, stick=E) 16 Label(self, text = '密码: ').grid(row=2, stick=W, pady=10) 17 Entry(self, textvariable=self.password, show='*').grid(row=2, column=1, stick=E) 18 Button(self, text='登陆', command=self.loginCheck).grid(row=3, stick=W, pady=10) 19 Button(self, text='退出', command=self.quit).grid(row=3, column=1, stick=E) 20 21 def loginCheck(self): 22 name = self.username.get() 23 secret = self.password.get() 24 if name=='wangliang' and secret=='123456': 25 self.destroy() 26 # MainPage() 27 else: 28 showinfo(title='错误', message='账号或密码错误!') 29 # print('账号或密码错误!') 30 31 root = Tk() 32 root.title('小程序') 33 width = 280 34 height = 200 35 screenwidth = root.winfo_screenwidth() 36 screenheight = root.winfo_screenheight() 37 alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2) 38 root.geometry(alignstr) # 居中对齐 39 40 page1 = LoginPage() 41 root.mainloop()
一个二次元的生物

浙公网安备 33010602011771号