首页 > 解决方案 > 通过按下另一个按钮来更改 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 什么也没做。有什么帮助吗?

标签: pythontkinter

解决方案


推荐阅读