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 什么也没做。有什么帮助吗?
解决方案
推荐阅读
- node.js - 哪个 heroku dynos 更适合 1500 多个活跃用户的应用程序?
- python - python中的类名未定义错误
- angular - 如何以角度将 json obj 值传递给 API(用于 post 方法)
- php - 如何选择组合框并输入到数据库
- linux - 如何在 .shell 脚本文件中传递参数
- azure - 如何使用 Powershell 在 Azure 中托管的服务上调用方法?
- html - CakePHP 3.7.1 向表单选择控件选项添加类
- orm - Coldfusion EntityLoad 读取计算字段
- sql - 如何选择总和但包含其他列?
- android-studio - 错误:“选择树中的配置元素以编辑其设置”