画布上的滚动条,该画布上带有框架

时间:2019-05-07 15:48:56

标签: python tkinter tkinter-canvas

我想制作一个带有滚动条的屏幕,所以我需要使用画布。但是,我想要按钮和标签在上面,所以我需要在上面放多个框架。一切都显示出来了,但是我不知道为什么滚动条实际上​​不起作用。

Entermems类(设置):

#WHAT HAPPENS IF YOU DON'T FILL ALL THE BOXES???????????
def __init__(self, master, numMembers):
    self.numMembers = numMembers
    self.master=master
    master.title("Enter Members")
    master.geometry("500x400")

    scrollbar = Scrollbar(self.master)

    canvas = Canvas(master, width = 500, height = 700, scrollregion=(0,0, 400, 400), yscrollcommand = scrollbar.set )

    scrollbar.pack(side = RIGHT, fill = Y)

    frame = Frame(master)

    scrollbar.configure(command = canvas.yview)


    #subWindow = canvas.create_window(0,0, window = frame)
    self.instructions = Label(frame, text = "Enter the names of your members below!",fg = "#7768ff", font = ("Arial", 20))
    self.instructions.pack()

    frame1 = Frame(master)
    #mainWindow = canvas.create_window(0,0, window=frame1)

    self.firstTitle = Label(frame1, text = "First Name",fg = "#7768ff", font = ("Arial", 15), pady=20, padx =20)
    self.lastTitle = Label(frame1, text = "Last Name", fg = "#7768ff", font = ("Arial", 15), pady=20, padx=20)
    self.instructions.grid(row=0, column = 2)
    self.firstTitle.grid(row=1, column=2)
    self.lastTitle.grid(row=1, column=3)


    self.dictionary1 = {}
    for i in range(1,101):
        x = "{}".format(i)
        self.dictionary1[x] = Entry(frame1)

    self.dictionary2 = {}
    for q in range(1, 101):
        y = "{}".format(q)
        self.dictionary2[y] = Entry(frame1)

    for j in range(1, (self.numMembers+1)):
        call = "{}".format(j)
        self.numbers=Label(frame1, text="{}".format(j))
        self.numbers.grid(row=j+2, column = 1)
        self.first = self.dictionary1[call]
        self.first.grid(row=j+2, column=2)
        self.last = self.dictionary2[call]
        self.last.grid(row=j+2, column =3)

    frame2 = Frame(master)
    #nextWindow = canvas.create_window(0,0, window=frame2)
    self.var1 = IntVar()
    self.yes = Checkbutton(frame2, text = "I acknowledge that once I click SUBMIT I cannot change this information", variable=self.var1, command = self.isChecked)
    self.submit = Button(frame2, text = "SUBMIT", command=self.selected)
    self.submit.configure(state=DISABLED)
    self.yes.pack()
    self.submit.pack()

    frame.pack()
    frame1.pack()
    frame2.pack()
    #canvas.pack()

    canvas.config(width=500,height=700)
    canvas.config(yscrollcommand=scrollbar.set)
    canvas.pack()

我希望滚动条正常工作

0 个答案:

没有答案