画图项目-界面实现
1 from tkinter import * 2 3 win_width = 900 4 win_height = 500 5 6 7 class Application(Frame): 8 9 def __init__(self, master=None, bgcolor='#000000'): 10 super().__init__(master) 11 self.master = master 12 self.bgcolor = bgcolor 13 self.pack() 14 self.createWidget() 15 16 def createWidget(self): 17 # 创建绘图区 18 drawpad = Canvas(root, width=win_width, height=win_height*0.9, bg=self.bgcolor) 19 drawpad.pack() 20 21 btn_start = Button(root, text='开始', name='start') 22 btn_start.pack(side='left', padx='10') 23 btn_pen = Button(root, text='画笔', name='pen') 24 btn_pen.pack(side='left', padx='10') 25 btn_rect = Button(root, text='矩形', name='rect') 26 btn_rect.pack(side='left', padx='10') 27 btn_clear = Button(root, text='清屏', name='clear') 28 btn_clear.pack(side='left', padx='10') 29 btn_earser = Button(root, text='橡皮擦', name='earser') 30 btn_earser.pack(side='left', padx='10') 31 btn_line = Button(root, text='直线', name='line') 32 btn_line.pack(side='left', padx='10') 33 btn_lineArrow = Button(root, text='箭头', name='lineArrow') 34 btn_lineArrow.pack(side='left', padx='10') 35 btn_color = Button(root, text='颜色', name='color') 36 btn_color.pack(side='left', padx='10') 37 38 39 if __name__ == '__main__': 40 root = Tk() 41 root.geometry(str(win_width)+'x'+str(win_height)+'+100+100') 42 root.title('绘图') 43 app = Application(master=root) 44 root.mainloop()