Python:使用 tkinter 递增 class 属性

Python: Incrementing class attributes with tkinter

这里有一个超级简单的 GUI 程序来帮助说明我的问题。它有:

如何让 self.button2 上显示的值在单击时增加?

from tkinter import *  

class Main:  

    def __init__(self):  
        main_window = Tk()

        self.x = 0

        self.button1 = Button(main_window,text=self.x,command=self.xplus1)
        self.button1.pack()
        self.button2 = Button(main_window,text='Quit',command=main_window.destroy)
        self.button2.pack()

        mainloop()

    def xplus1(self):
        self.x = self.x + 1

Main()

self.button1.config(text=self.x)添加到xplus1(self)的定义中:

    def xplus1(self):
         self.x = self.x + 1
         self.button1.config(text=self.x)