Wie erstelle ich einen abgerundeten Knopf?Python

Python-Programme
Anonymous
 Wie erstelle ich einen abgerundeten Knopf?

Post by Anonymous »

Ich versuche, mit Tkinter abgerundete Schaltflächen für mein Skript zu erhalten.

Code: Select all

from tkinter import *
import tkinter as tk

class CustomButton(tk.Canvas):
def __init__(self, parent, width, height, color, command=None):
tk.Canvas.__init__(self, parent, borderwidth=1,
relief="raised", highlightthickness=0)
self.command = command

padding = 4
id = self.create_oval((padding,padding,
width+padding, height+padding), outline=color, fill=color)
(x0,y0,x1,y1)  = self.bbox("all")
width = (x1-x0) + padding
height = (y1-y0) + padding
self.configure(width=width, height=height)
self.bind("", self._on_press)
self.bind("", self._on_release)

def _on_press(self, event):
self.configure(relief="sunken")

def _on_release(self, event):
self.configure(relief="raised")
if self.command is not None:
self.command()
app = CustomButton()
app.mainloop()
< /code>
, aber ich erhalte den folgenden Fehler: < /p>
TypeError: __init__() missing 4 required positional arguments: 'parent', 'width', 'height', and 'color'

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post