告诉我如何正确组织从 tkinter.Button 继承的按钮(添加图标(通过添加属性改进标准 tkinter.Button))
到目前为止,我已经停在那里了。我的错误是什么?如何正确组织pack()的工作?
from tkinter import *
root = Tk()
class myButton(Button):
def __init__(self, text, width, height):
self._text = text
self._width = width
self._height = height
def text(self, _text):
text = _text
def width(self, _width):
width = _width
def height(self, _height):
height = _height
b2 = myButton(text="Изменить", width=15, height=3)
b2.pack()
root.mainloop()
打印属性
我想在打印示例中添加更多属性,但是没有用,为什么?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tkinter import *
root = Tk()
class myButton(Button):
def __init__(self, text, width, height, print): #Испр.
super().__init__(text=text, width=width, height=height)
self._text = text
self._width = width
self._height = height
self._print = print #Испр.
def text(self, _text):
text = _text
def width(self, _width):
width = _width
def height(self, _height):
height = _height
def print(self, _print): #Испр.
print(_print) #Испр.
b2 = myButton(text="123", width=15, height=3, print = "111") #Испр.
b2.pack()
root.mainloop()
好吧,您重写了
__init__
父类的方法,并且在其中执行了重要操作。因此,您必须在代码中重现它们,或者添加__init__
来自父类的调用:原来是做这样的事情......(试图学习如何重新定义类)
还有一个问题,如果通话不完整:
简短:
如何找出参数的名称:文本、宽度、高度等...?如果您输入谷歌,https://www.tutorialspoint.com/python/tk_button.htm 并阅读选项(如本链接所示),它们是否符合现实?