我試圖用ttk.Scrollbar
滾動畫布,但我無法成功。當我縮小應用程序窗口時,窗口小部件會縮小,並且scrollbar
不起作用。我找到了一些關於scrollbar
的例子,但是沒有與python 3
和/或我的代碼匹配。你能糾正我的代碼嗎?這裏是我的代碼:被添加到畫布pack
,place
或grid
不會滾動tkinter畫布滾動條不能用於類
from tkinter import *
from tkinter import ttk
class Uygulama(ttk.Frame):
def __init__(self):
ttk.Frame.__init__(self)
self.master.geometry('600x500')
self.pack(expand="true",
fill="both"
)
self.Cerceveler()
self.GuiAraclari()
self.AnaMenu()
def AnaMenu(self,master=None):
self.anamenu=Menu()
self.master.config(menu=self.anamenu)
self.dosya=Menu(self.anamenu)
self.anamenu.add_cascade(label="File",
menu=self.dosya)
self.dosya.add_command(label="Aç")
self.dosya.add_command(label="Kaydet")
self.dosya.add_command(label="Farklı Kaydet")
self.dosya.add_command(label="Çıkış",
command=self.master.quit)
def Cerceveler(self):
self.root_canvas=Canvas(self,
relief="groove",
borderwidth=0,
scrollregion=(0, 0, 1200, 800))
self.root_canvas.pack(side="left",
fill="both",
expand="true",
)
self.ust_cerceve=ttk.Frame(self.root_canvas,
relief="groove",
borderwidth=2,
)
self.ust_cerceve.pack(expand="false",
fill="x",
side="top")
self.orta_cerceve=ttk.Frame(self.root_canvas,
relief="flat",
borderwidth=0,
)
self.orta_cerceve.pack(side="top",
expand="true",
fill="both")
self.alt_cerceve=ttk.Frame(self.root_canvas,
relief="groove",
borderwidth=2,
)
self.alt_cerceve.pack(side="bottom",
expand="false",
fill=X)
self.sol_cerceve=ttk.Frame(self.orta_cerceve,
width=200,
relief="groove",
borderwidth=2,
)
self.sol_cerceve.pack(side="left",
fill="y",
expand="false")
self.sag_cerceve=ttk.Frame(self.orta_cerceve,
relief="flat",
borderwidth=2)
self.sag_cerceve.pack(side="left",
fill= "both",
expand="true")
self.kaydirma=ttk.Scrollbar(self,
orient="vertical",
command=self.root_canvas.yview)
self.kaydirma.pack(side="right",
expand="false",
fill="y")
self.root_canvas.configure(yscrollcommand=self.kaydirma.set,
)
def GuiAraclari(self):
self.bilgiekrani=ttk.Entry(self.alt_cerceve)
self.bilgiekrani.pack(fill=X)
self.deneme1=ttk.Button(self.ust_cerceve,
text="Deneme1")
self.deneme1.pack(side="left")
self.deneme2=ttk.Button(self.ust_cerceve,
text="Deneme2")
self.deneme2.pack(side="left")
self.deneme3=ttk.Button(self.ust_cerceve,
text="Deneme")
self.deneme3.pack(side="left")
self.deneme4=ttk.Button(self.sag_cerceve,
text="Deneme4")
self.deneme4.pack()
self.deneme5=ttk.Button(self.sag_cerceve,
text="Deneme5")
self.deneme5.pack()
self.deneme6=ttk.Button(self.sag_cerceve,
text="Deneme6")
self.deneme6.pack()
self.deneme7=ttk.Button(self.sag_cerceve,
text="Deneme7")
self.deneme7.pack()
if __name__ == '__main__':
app=Uygulama()
app.update()
app.mainloop()