canvas.create_text(event.x, event.y, font=("微软雅黑", int(size)),text=text,fill=foreColor) what.set(1) #按住鼠标左键移动,画图 def onLeftButtonMove(event): global lastDraw if yesno.get()==0: return if what.get()==1: #使用当前选择的前景色绘制曲线 lastDraw=canvas.create_line(X...
canvas.create_text(20, 30, anchor=W, font="Purisa", text="大多数关系似乎都是短暂的") canvas.create_text(20, 60, anchor=W, font="Purisa", text="它们很好,但不是永久的") canvas.create_text(20, 130, anchor=W, font="Purisa", text="谁不渴望有人抱着") canvas.create_text(20, 16...
self.canvas.create_rectangle(x1, y1, x2, y2)if __name__ == '__main__':root = Tk()root.title('Cancas画布测试')root.geometry('400x300+200+300')app = Application(root)root.mainloop() 运行结果 点击画十个矩形的按钮后 二、Text文本框的使用 代码演示 import tkinter as tkfrom tkinter i...
canvas=Canvas(win,width=200,height=200,bg="#AAAAAA").pack() win.mainloop() 1. 2. 3. 4. 5. 6. 二 绘制线条 fromtkinterimport* win=Tk() win.title("创建画布") win.geometry("600x400") canvas=Canvas(win,width=600,height=400,bg="#AAAAAA") line1=canvas.create_line(*(14,65,66,...
在View的onDraw方法中绘制文本,可以使用Canvas.drawText方法来绘制指定位置的文本。 在View的onTouchEvent方法中处理触摸事件,通过判断触摸事件的类型,可以实现文本的拖拽效果。 在触摸事件的ACTION_DOWN事件中记录下触摸点的初始位置。 在触摸事件的ACTION_MOVE事件中计算出手指移动的距离,并更新文本的位置。
draw_text.py #!/usr/bin/python from tkinter import Tk, Canvas, Frame, BOTH, W class Example(Frame): def __init__(self): super().__init__() self.initUI() def initUI(self): self.master.title("Lyrics") self.pack(fill=BOTH, expand=1) ...
text = 'Use Canvas', fill = 'blue') canvas.pack() # 将Canvas添加到主窗口 root.mainloop() 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. wxpython 的canvas # create a canvas on top of a blank bitmap ...
canvas_dc.SetBrush(wx.Brush('white')) canvas_dc.Clear() # draw a bunch of circles ... # pen colour canvas_dc.SetPen(wx.Pen('red', 1)) # fill colour canvas_dc.SetBrush(wx.Brush('yellow')) for x in range(10, 180, 10): ...
# create the canvas on top of the draw_bmp canvas_dc = wx.MemoryDC(draw_bmp) # fill the canvas white canvas_dc.SetBrush(wx.Brush('white')) canvas_dc.Clear() # draw a bunch of circles ... # pen colour canvas_dc.SetPen(wx.Pen('red', 1)) # fill colour canvas_dc.SetBrush(wx...
canvas_dc.SetBrush(wx.Brush('white')) canvas_dc.Clear() # draw a bunch of circles ... # pen colour canvas_dc.SetPen(wx.Pen('red', 1)) # fill colour canvas_dc.SetBrush(wx.Brush('yellow')) for x in range(10, 180, 10): y = x r = x canvas_dc.DrawCircle(...