0
我正在嘗試在Python中創建一個粘滯便箋程序來練習。我想創建一個按鈕,當點擊時,文本框的背景變成黃色。我的代碼如下:用Tkinter中的按鈕更改背景顏色
from tkinter import *
import random
color = ['burlywood2', 'seagreen1', 'steelblue1', 'gold']
randomColor = random.choice(color)
class Sticky(Frame):
def __init__(self, master):
Frame.__init__(self, master)
master.minsize(width=250, height=200)
master.configure(background=randomColor)
self.pack(fill=BOTH, expand=YES)
self.txtEntry = Text(background=randomColor, highlightthickness=0, relief=RAISED)
self.txtEntry.pack(fill=BOTH, expand=YES)
myString = input("Enter your text here: ")
self.txtEntry.insert(END, myString)
self.createWidgets()
def createWidgets(self):
self.QUIT = Button(self)
self.QUIT["text"] = "Completed"
self.QUIT["fg"] = "white"
self.QUIT["background"] = "green"
self.QUIT["command"] = self.quit
self.QUIT.pack(fill=BOTH, expand=YES)
self.URGENT = Button(self)
self.URGENT["text"] = "URGENT"
self.URGENT["fg"] = "yellow"
self.URGENT["background"] = "red"
self.URGENT["command"] = self.highLight()
self.URGENT.pack(fill=BOTH, expand=YES)
def highLight(txtEntry):
txtEntry.configure(background='yellow')
txtEntry.update()
我似乎無法得到它的工作。當點擊「緊急」按鈕時,沒有任何反應。感謝您的任何建議
非常感謝你的幫助! –