編輯[已解決]
根據下面
在視頻中,下面有更多元素,template47但我無法滾動到它們。我可以向上滾動,但那里很孤獨。所有名稱實際上都是帶有零bd和 的按鈕HLthickness。
我試過的
首先,我的第一直覺是將 a 附加ttk.scrollbar到canvas frame,我這樣做了,但觀察到了完全相同的行為。
然后我試著看看我是否可以.moveTo('1.0')用來向下滾動到最后一個條目,然后因為向上滾動已經有效,應該沒有問題。但這也沒有任何作用。元素仍然被切斷,顯然向上滾動也搞砸了。
I don't think I can use pack/grid geoManagers since as the answer by bryan i linked to above suggests, using place with its in_ arg is the preferred way. If it is possible otherwise, let me know though.
my use case in a nutshell
as depicted in the answer linked above, I also have two frames, and I'm using the on_click callback function to switch parents (a lot like in example code in answer). Turned out place was the best bet to achieve this. and it is, all of that aspect is working well. It's just the scroll thingy which doesn't work.
some code (dare i say MCVE)
how i bind to mousewheel
def _bound_to_mousewheel(self, event):
self.canvas.bind_all("<MouseWheel>", self._on_mousewheel)
def _unbound_to_mousewheel(self, event):
self.canvas.unbind_all("<MouseWheel>")
def _on_mousewheel(self, event):
self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
creating the window
self.canvas.create_window((5, 6), window=self.scrolled_frame, anchor="w")
ad of course the widgets inside
for f in self.fav_templates:
btn = tk.Button(self.root, text='text', command=lambda te=f: self._on_click(te))
btn.place(in_=self.ft_frame, x=20, y=p)
So
I'm sure above snippets would give idea of what I've done. If someone needs me to create a complete MCVE they can run, happy to do that, lemme know.
What did I miss in the setup? any ideas or suggestion are welcome.
Thank You :)
uj5u.com熱心網友回復:
主要問題是您正在使用place并且使用地方您將成為小部件的全能者,這意味著主程式或后臺提供的任何其他魔術tkinter 將沒有
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/398972.html
