我有以下代码,一个带有画布和一些按钮的简单窗口,一个位于画布内,另一个位于画布旁边。
问题是,当我向上或向下滚动时,按钮"查看"当它想到时根本不移动def initUI(self):
self.content = Canvas()
self.parent.title("window")
self.style = Style()
self.style.theme_use("default")
self.content.pack(fill=BOTH, expand=1)
self.vbar=Scrollbar(self,orient=VERTICAL)
self.vbar.pack(side=RIGHT,fill=Y)
self.vbar.config(command=self.content.yview)
self.content.config(yscrollcommand=self.vbar.set)
outButton = Button(self, text="I'm out", command=lambda: self.buttonOut())
outButton.pack(side=RIGHT)
view = Button(self.content, text="View Profile", command=someting)
view.place(x=235, y=160)
self.pack()
任何建议?
答案 0 :(得分:2)
终于找到了解决方案,只需将按钮添加到窗口,将此窗口添加到画布
def initUI(self):
self.content = Canvas()
self.parent.title("window")
self.style = Style()
self.style.theme_use("default")
self.content.pack(fill=BOTH, expand=1)
self.vbar=Scrollbar(self,orient=VERTICAL)
self.vbar.pack(side=RIGHT,fill=Y)
self.vbar.config(command=self.content.yview)
self.content.config(yscrollcommand=self.vbar.set)
outButton = Button(self, text="I'm out", command=lambda: self.buttonOut())
outButton.pack(side=RIGHT)
view = Button(self.content, text="View Profile", command=someting)
- view.place(x=235, y=160)
+ button_window = self.content.create_window(235, 160, window=view)
self.pack()