擅长:python、mysql、java
<p>我通过修改ttk.数字调整框在继承上述问题中的类之前,要使用生成的<code><<Increment>></code>和<code><<Decrement>></code>事件:</p>
<pre><code>class UpDownSpinbox(ttk.Spinbox):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# bind the events that are triggered by pressing an arrow button
self.bind("<<Increment>>", self._do_on_increment)
self.bind("<<Decrement>>", self._do_on_decrement)
def _do_on_increment(self, *args, **kwargs):
self.do_upon_clicking_arrows("up")
# optional, prevent the event handler from doing other things by returning "break"
return("break")
def _do_on_decrement(self, *args, **kwargs):
self.do_upon_clicking_arrows("down")
# optional, prevent the event handler from doing other things by returning "break"
return("break")
def do_upon_clicking_arrows(self, direction):
print(direction)
</code></pre>
<p>然后呢</p>
^{pr2}$
<p>按下这些按钮后,它会将“向上”或“向下”打印到控制台。当然,<code>do_upon_clicking_arrows()</code>函数可以代替任何具有所需行为的东西。在</p>