小编Lel*_*sin的帖子

如何获取Tkinter小部件属性?

我创建了一个Button,并设置了它的回调,但是如何获得按钮的属性fg呢?

from Tkinter import *

def callback(self):
    tkMessageBox.showinfo("button", color)

top = Tk()
frame = Frame(top)
frame.pack()

greenbutton = Button(frame, text="Brown", fg="brown", command=callback)
greenbutton.pack( side = RIGHT )

bluebutton = Button(frame, text="Blue", fg="blue", command=callback)
bluebutton.pack( side = LEFT )

top.mainloop()
Run Code Online (Sandbox Code Playgroud)

我只想点击蓝色按钮,它会告诉我它是蓝色的.

python tkinter

0
推荐指数
2
解决办法
6963
查看次数

标签 统计

python ×1

tkinter ×1