目前这是计划的一部分:
self.tabs = Notebook(root)
self.tabs.grid(column=0, row=0)
self.frame1 = Frame()
self.frame2 = Frame()
self.frame3 = Frame()
self.frame4 = Frame()
self.frame5 = Frame()
self.frame6 = Frame()
self.framemain = Frame()
self.framemain.grid(column=1, row=0)
def buttonCreate(frameCount):
buttonhatsforward = Button(self.frame1, image=self.forwardrender, command=select.buttonHatsForwardClicked).grid(column=3, row=0)
button1 = Button(frameCount, text = "hello")
button1.grid(column=0, row=1, sticky=W)
button2 = Button(frameCount, text = "hello")
button2.grid(column=1, row=1, sticky=W)
button3 = Button(frameCount, text = "hello")
button3.grid(column=2, row=1, sticky=W)
button4 = Button(frameCount, text = "hello")
button4.grid(column=3, row=1, sticky=W)
button5 = Button(frameCount, text = "hello")
button5.grid(column=4, row=1, sticky=W)
button6 = Button(frameCount, text = "hello")
button6.grid(column=0, row=2, sticky=W)
button7 = Button(frameCount, text = "hello")
button7.grid(column=1, row=2, sticky=W)
button8 = Button(frameCount, text = "hello")
button8.grid(column=2, row=2, sticky=W)
button9 = Button(frameCount, text = "hello")
button9.grid(column=3, row=2, sticky=W)
button10 = Button(frameCount, text = "hello")
button10.grid(column=4, row=2, sticky=W)
button11 = Button(frameCount, text = "hello")
button11.grid(column=0, row=3, sticky=W)
button12 = Button(frameCount, text = "hello")
button12.grid(column=1, row=3, sticky=W)
button12 = Button(frameCount, text = "hello")
button13.grid(column=2, row=3, sticky=W)
button13 = Button(frameCount, text = "hello")
button13.grid(column=3, row=3, sticky=W)
button14 = Button(frameCount, text = "hello")
button14.grid(column=4, row=3, sticky=W)
buttonCreate(self.frame1)
buttonCreate(self.frame2)
buttonCreate(self.frame3)
buttonCreate(self.frame4)
buttonCreate(self.frame5)
buttonCreate(self.frame6)
self.tab1 = self.tabs.add(self.frame1, text="tab1")
self.tab2 = self.tabs.add(self.frame2, text="tab2")
self.tab3 = self.tabs.add(self.frame3, text="tab3")
self.tab4 = self.tabs.add(self.frame4, text="tab4")
self.tab5 = self.tabs.add(self.frame5, text="tab5")
self.tab6 = self.tabs.add(self.frame6, text="tab6")
它的作用是制作一个框架,向其添加按钮,然后将其添加到某些标签。问题在于,当我执行self.button1.config(text="cookie")
时,它指的是最后一帧。如何制作它以便我可以单独访问每个按钮?
答案 0 :(得分:0)
@ TigerhawkT3,谢谢你让我跳出框框思考。我快速淋浴,然后我意识到我可以做到:return(button1, button2, button3, button4, button5, button6, button7, button8, button9, button10, button11, button12, button13, button14)
,然后将我的buttonCreate
功能修改为a = buttonCreate(self.frame1)
,最后修改为a[2].configure(text="cake", compound=LEFT)
。
虽然返回14个按钮并不是一个好主意,但我会继续努力让它变得更纤细,更整洁。惭愧你没有留下答案,我会赞成你。 :(