uhmwpepython之canvas画布canvas 画布
canvas(画布)是⼀个矩形区域,可以放置图形、图像、组件等。
from tkinter import *
import random
from tkinter import messagebox
class Application(Frame):
"""⼀个经典的GUI程序的写法"""
somebody needs you
suggestiondef__init__(lf, master=None):
super().__init__(master) # super代表的是⽗类的定义,⽽不是⽗类对象
lf.master = master
lf.pack()
def createWidget(lf):
"""创建组件"""
考公务员的学历要求>snapbacklf.canvas = Canvas(lf, width=400, height=350, bg='blue')
lf.canvas.pack()
line = ate_line(12, 12, 24, 24, 39, 52)
# 画⼀条直线
rect = ate_rectangle(50, 50, 100, 100)
# 画⼀个矩形
oval = ate_oval(50, 50, 100, 100)
# 画⼀个圆,坐标两双,为圆的边界矩形左上⾓和底部右下⾓estc
global pthoto
pthoto = PhotoImage(file='20191117174112450.gif')
ate_image(160, 160, image=pthoto)
Button(lf, text='画⼗个圆', Oval).pack(side='left')
def tenOval(lf):describe
for i in range(0, 10):
fuzex1 = random.randrange(int(lf.canvas['width']) / 2)
swallowingx2 = random.randrange(int(lf.canvas['height']) / 2)
y1 = 9 + random.randrange(int(lf.canvas['width']) / 2)
y2 = 9 + random.randrange(int(lf.canvas['height']) / 2)
ate_oval(x1, x2, y1, y2)
if__name__ == "__main__":
root = Tk()日语翻译器
app = Application(master=root)
root.mainloop()