나는 tkinter를 사용하여 스크립트를위한 둥근 버튼을 얻으려고합니다. 둥근 버튼 tkinter 파이썬
는 다음 코드 발견 :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("<ButtonPress-1>", self._on_press)
self.bind("<ButtonRelease-1>", 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()
을하지만, 나는 다음과 같은 오류 얻을 :
TypeError: __init__() missing 4 required positional arguments: 'parent', 'width', 'height', and 'color'
감사합니다. 그건 실행했지만 버튼이 둥근 아니 –
아니, 아니에요. 그러나 정확히 "발견 한"코드가 수행해야하는 작업입니다. 그것은 기복이있는 사각 캔버스를 만들고 그것에 타원을 그립니다. 버튼을 눌렀다 떼면 안도가 올라가고 다시 올립니다. – avysk