ساخت برنامه paint با tkinter پایتون قسمت سوم


سلام به همگی، امروز میخوایم به برناممون یک اسلایدر اضافه کنیم که سایز نوک خودکار رو تعیین کنه. این کار دو تا مرحله داره.

قدم اول: اضافه کردن خود اسلایدر به بالای بوم نقاشی.

class App(Tk):
      color=&quot#0A0&quot 
      o=HORIZONTAL
      properties_scl=dict(from_=1,to=100,tickinterval=10,length=700)
      def __init__(self):
           super().__init__()
           self.title(&quotPaint&quot)
           self.geometry(&quot1200x1440&quot)
           self.resizable(0,0)
           self.pensize=Scale(**self.properties_scl,orient=self.o,showvalue=1)
           self.pensize.place(x=100,y=32)
           self.cnv=Canvas(width=1200,height=1140,bg=&quot#fff&quot)
           self.cnv.place(x=0,y=300)
     def paint(self,event):
         p=10
          x1,y1=event.x-p,event.y-p
          x2,y2=event.x+p,event.y-p
          self.cnv.create_oval(x1,y1,x2,y2,fill=self.color,outline=self.color)
App()
mainloop()

قدم دوم: فرستادن عدد اسلایدر به متد نقاشی.

class App(Tk):
      color=&quot#0A0&quot 
      o=HORIZONTAL
      properties_scl=dict(from_=1,to=100,tickinterval=10,length=700)
      def __init__(self):
           super().__init__()
           self.title(&quotPaint&quot)
           self.geometry(&quot1200x1440&quot)
           self.resizable(0,0)
           self.pensize=Scale(**self.properties_scl,orient=self.o,showvalue=1)
           self.pensize.place(x=100,y=32)
           self.cnv=Canvas(width=1200,height=1140,bg=&quot#fff&quot)
           self.cnv.place(x=0,y=300)
     def paint(self,event):
         p=self.pensize.get()
          x1,y1=event.x-p,event.y-p
          x2,y2=event.x+p,event.y-p
          self.cnv.create_oval(x1,y1,x2,y2,fill=self.color,outline=self.color)
App()
mainloop()

بحث امروز هم به پایان رسید. خداحافظ.