【发布时间】:2018-03-01 13:24:20
【问题描述】:
让我详细说明这个过程。以下是我的应用的示例代码sn-p
import tkinter as tk
class ldo(Frame):
def __init__(self, master = None):
Frame.__init__(self,master)
self.grid()
self.appOutline()
def appOutline(self):
self.masterframe1 = Frame(self.master,width=300,height=300)
self.masterframe1.grid(sticky=N,padx=20)
self.masterframe2 = Frame(self.master,width=300,height=100)
self.masterframe2.grid(sticky=S,padx=20)
self.addtabbutton = Button(self.masterframe2,text="Add Step", width=10, command=self.popup2, bg="sienna1")
self.addtabbutton.grid(row=0,column=0,sticky=EW)
self.runallbutton = Button(self.masterframe2,text="Run All", width=10, command=self.underprocess, bg="sienna1",state=DISABLED)
self.runallbutton.grid(row=0,column=1,sticky=EW)
self.runselbutton = Button(self.masterframe2,text="Run Selected", width=10, command=self.popup2, bg="sienna1",state=DISABLED)
self.runselbutton.grid(row=0,column=2,sticky=EW)
def popup2(self):
self.child = Toplevel()
self.child.geometry("300x300")
self.child.title("Secondary")
self.label1 = Label(self.child,text="Your input")
self.label1.pack()
self.entryinp = StringVar()
self.entry1 = Entry(self.child,textvariable=entryinp)
self.entry1.pack()
self.submit = Button(self.child,text="Submit",command=self.evaluation,bg="pink")
self.submit.pack()
def evaluation(self):
self.inputValue = self.entry1.get()
self.steps = Button(self.masterframe1,text=self.inputValue,command=self.colorchange,bg="light blue")
self.steps.pack()
self.runallbutton.config(state=NORMAL)
self.child.destroy()
def colorchange(self):
self.steps.config(bg="white")
self.runselbutton.config(state=NORMAL)
def underprocess(self):
print("processing...")
if __name__ == "__main__":
app = ldo()
app.master.title("Primary")
app.mainloop()
下面的屏幕截图是我的应用程序的输出。我的需要是我想更改我在主界面中单击的按钮的颜色,但是无论我单击什么按钮,它都会改变最后一个按钮的颜色。我尝试使用 lambda,但我怀疑我是否正确使用它。上面的 sn-p 正在工作,除了颜色变化部分。请指导我如何完成这项工作。
另外,我希望“运行选定”按钮打印(文本)我单击的那个特定按钮。
P.S.:我也签入了this link,但无法解决。
【问题讨论】:
标签: python python-3.x tkinter