通过按下另一个按钮来更改tkinter按钮的颜色

时间:2019-03-20 01:53:55

标签: python tkinter

我想通过按Button1来更改Button2的背景颜色。这是我的工作:

from Tkinter import *

class Application():
    def __init__(self, root):
        self.root = root
        self.Frame = Frame(self.root)
        self.Frame.pack()

        self.Button1 = Button(self.Frame, text = "Button 1", command = self.button1_press)
        self.Button1.pack()

        self.Button2 = Button(self.Frame, text = "Button 2")
        self.Button2.pack()

    def button1_press(self):
        self.Button2.config(bg = "red")

root = Tk()
app = Application(root)
root.mainloop()

但是按按钮1则无济于事。有帮助吗?

0 个答案:

没有答案
相关问题