滚动条不起作用和多选复选框

时间:2017-03-14 07:59:20

标签: python checkbox tkinter widget scrollbars

我的Python Tkinter代码有两个问题,右边的窗口框中有一系列按钮和复选框:

  1. 滚动条仅适用于绘制的框和文本,但按钮和复选框不会移动。

  2. 我想使用某些复选框来选择较低级别的复选框。

    例1:顶部的复选框1选中它下面4行中的所有复选框。

    例2:每行上8个按钮正上方的所有复选框都会选中其下方的所有8个复选框,例如复选框s14选中底行的所有复选框(复选框141到148)。

    例3:根据需要选择一个到多个复选框(从技术上讲,这适用于单个选择,但我的代码的先前版本使得选择一个复选框全部选中它们,这是不希望的 - 所以我删除了此代码)。

  3. 我希望能够就如何完成这些任务找到方向。任何建议将不胜感激。

    代码:

    from Tkinter import *
    
    class GUI(Frame, Toplevel):
    
        def __init__(self, master):
    
            Frame.__init__(self, master)
            self.master = master
            self.initUI()
    
        def initUI(self):
    
            self.master.title('Test GUI')
            self.pack(fill=BOTH, expand=1, side=RIGHT)
    
            self.left_fra = Frame(self.master, bg='grey', bd=2)
            self.left_fra.pack(side=LEFT, anchor=NW, ipadx=5, ipady=400)
            Label(self.left_fra, text="Test GUI", bg='light blue', justify=CENTER, font=('Tahoma', 20)).pack(padx=5,pady=5)
    
            self.frame = Frame(self.master)
            self.right_fra = Canvas(self.frame, bg='light blue', bd=2, scrollregion=(0,0,1400,700))
    
            self.right_fra.pack(side=RIGHT, anchor=E, ipadx=800, ipady=400, fill=BOTH)
            self.frame.pack(expand=False, padx=0,pady=0)
    
            self.right_fra.create_rectangle(1100, 135, 1326, 578, outline="black")
            self.right_fra.create_rectangle(1100, 165, 1326, 273, outline="black")
            self.right_fra.create_rectangle(1100, 165, 1326, 373, outline="black")
            self.right_fra.create_rectangle(1100, 165, 1326, 473, outline="black")
    
            self.r1_Checkbox = Checkbutton(self.right_fra, bg='light blue', text="1", font=(20))
            self.r1_Checkbox.place(x=1115, y=136)
    
            self.s11_Checkbox = Checkbutton(self.right_fra, bg='light blue', text="1-1", font=(20))
            self.s11_Checkbox.place(x=1115, y=175)
    
            self.s12_Checkbox = Checkbutton(self.right_fra, bg='light blue', text="1-2", font=(20))
            self.s12_Checkbox.place(x=1115, y=275)
    
            self.s13_Checkbox = Checkbutton(self.right_fra, bg='light blue', text="1-3", font=(20))
            self.s13_Checkbox.place(x=1115, y=375)
    
            self.s114_Checkbox = Checkbutton(self.right_fra, bg='light blue', text="1-4", font=(20))
            self.s114_Checkbox.place(x=1115, y=475)
    
            self.f111_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n1\n1")
            self.f111_Button.place(x=1115, y=200)
    
            self.f112_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n1\n2")
            self.f112_Button.place(x=1141, y=200)
    
            self.f113_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n1\n3")
            self.f113_Button.place(x=1167, y=200)
    
            self.f114_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n1\n4")
            self.f114_Button.place(x=1193, y=200)
    
            self.f115_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n1\n5")
            self.f115_Button.place(x=1219, y=200)
    
            self.f116_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n1\n6")
            self.f116_Button.place(x=1245, y=200)
    
            self.f117_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n1\n7")
            self.f117_Button.place(x=1271, y=200)
    
            self.f118_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n1\n8")
            self.f118_Button.place(x=1297, y=200)
    
            self.f111_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f111_Checkbox.place(x=1115, y=248)
    
            self.f112_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f112_Checkbox.place(x=1141, y=248)
    
            self.f113_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f113_Checkbox.place(x=1167, y=248)
    
            self.f114_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f114_Checkbox.place(x=1193, y=248)
    
            self.f115_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f115_Checkbox.place(x=1219, y=248)
    
            self.f116_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f116_Checkbox.place(x=1245, y=248)
    
            self.f117_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f117_Checkbox.place(x=1271, y=248)
    
            self.f118_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f118_Checkbox.place(x=1297, y=248)
    
            self.f121_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n2\n1")
            self.f121_Button.place(x=1115, y=300)
    
            self.f122_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n2\n2")
            self.f122_Button.place(x=1141, y=300)
    
            self.f123_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n2\n3")
            self.f123_Button.place(x=1167, y=300)
    
            self.f124_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n2\n4")
            self.f124_Button.place(x=1193, y=300)
    
            self.f125_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n2\n5")
            self.f125_Button.place(x=1219, y=300)
    
            self.f126_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n2\n6")
            self.f126_Button.place(x=1245, y=300)
    
            self.f127_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n2\n7")
            self.f127_Button.place(x=1271, y=300)
    
            self.f128_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n2\n8")
            self.f128_Button.place(x=1297, y=300)
    
            self.f121_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f121_Checkbox.place(x=1115, y=348)
    
            self.f122_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f122_Checkbox.place(x=1141, y=348)
    
            self.f123_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f123_Checkbox.place(x=1167, y=348)
    
            self.f124_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f124_Checkbox.place(x=1193, y=348)
    
            self.f125_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f125_Checkbox.place(x=1219, y=348)
    
            self.f126_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f126_Checkbox.place(x=1245, y=348)
    
            self.f127_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f127_Checkbox.place(x=1271, y=348)
    
            self.f128_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f128_Checkbox.place(x=1297, y=348)
    
            self.f131_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n3\n1")
            self.f131_Button.place(x=1115, y=400)
    
            self.f132_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n3\n2")
            self.f132_Button.place(x=1141, y=400)
    
            self.f133_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n3\n3")
            self.f133_Button.place(x=1167, y=400)
    
            self.f134_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n3\n4")
            self.f134_Button.place(x=1193, y=400)
    
            self.f135_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n3\n5")
            self.f135_Button.place(x=1219, y=400)
    
            self.f136_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n3\n6")
            self.f136_Button.place(x=1245, y=400)
    
            self.f137_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n3\n7")
            self.f137_Button.place(x=1271, y=400)
    
            self.f138_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n3\n8")
            self.f138_Button.place(x=1297, y=400)
    
            self.f131_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f131_Checkbox.place(x=1115, y=448)
    
            self.f132_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f132_Checkbox.place(x=1141, y=448)
    
            self.f133_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f133_Checkbox.place(x=1167, y=448)
    
            self.f134_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f134_Checkbox.place(x=1193, y=448)
    
            self.f135_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f135_Checkbox.place(x=1219, y=448)
    
            self.f136_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f136_Checkbox.place(x=1245, y=448)
    
            self.f137_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f137_Checkbox.place(x=1271, y=448)
    
            self.f138_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f138_Checkbox.place(x=1297, y=448)
    
            self.f141_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n4\n1")
            self.f141_Button.place(x=1115, y=500)
    
            self.f142_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n4\n2")
            self.f142_Button.place(x=1141, y=500)
    
            self.f143_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n4\n3")
            self.f143_Button.place(x=1167, y=500)
    
            self.f144_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n4\n4")
            self.f144_Button.place(x=1193, y=500)
    
            self.f145_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n4\n5")
            self.f145_Button.place(x=1219, y=500)
    
            self.f146_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n4\n6")
            self.f146_Button.place(x=1245, y=500)
    
            self.f147_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n4\n7")
            self.f147_Button.place(x=1271, y=500)
    
            self.f148_Button = Button(self.right_fra, width=4, font=('tahoma', 6), text="BU\n1\n4\n8")
            self.f148_Button.place(x=1297, y=500)
    
            self.f141_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f141_Checkbox.place(x=1115, y=548)
    
            self.f142_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f142_Checkbox.place(x=1141, y=548)
    
            self.f143_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f143_Checkbox.place(x=1167, y=548)
    
            self.f144_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f144_Checkbox.place(x=1193, y=548)
    
            self.f145_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f145_Checkbox.place(x=1219, y=548)
    
            self.f146_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f146_Checkbox.place(x=1245, y=548)
    
            self.f147_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f147_Checkbox.place(x=1271, y=548)
    
            self.f148_Checkbox = Checkbutton(self.right_fra, bg='light blue')
            self.f148_Checkbox.place(x=1297, y=548)
    
            self.hbar = Scrollbar(self.right_fra, orient=HORIZONTAL)
            self.hbar.config(command=self.right_fra.xview)
            self.hbar.pack(fill=BOTH, side=BOTTOM)
            self.vbar = Scrollbar(self.right_fra, orient=VERTICAL)
            self.vbar.config(command=self.right_fra.yview)
            self.vbar.pack(fill=BOTH, side=RIGHT)
            self.right_fra.config(xscrollcommand=self.hbar.set, yscrollcommand=self.vbar.set)
    
    class Controller:
    
        def __init__(self, root):
    
            self.root = root
            self.view = GUI(self.root)
    
    if __name__ == '__main__':
        root = Tk()
        myapp = GUI(root)
        root.mainloop()
    

0 个答案:

没有答案