F
F
Fizl2020-12-28 12:22:41
Python
Fizl, 2020-12-28 12:22:41

How to display Button, each of which has database data?

class VerticalScrolledFrame2(Frame):
    def __init__(self, parent, *args, **kw):
        Frame.__init__(self, parent, *args, **kw)            

        # create a canvas object and a vertical scrollbar for scrolling it
        vscrollbar = Scrollbar(self, orient=VERTICAL)
        vscrollbar.pack(fill=Y, side=RIGHT, expand=FALSE)
        canvas = Canvas(self, bd=0, highlightthickness=0,
                        yscrollcommand=vscrollbar.set,height = 470,width = 70)
        canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
        vscrollbar.config(command=canvas.yview)

        # reset the view
        canvas.xview_moveto(0)
        canvas.yview_moveto(0)

        # create a frame inside the canvas which will be scrolled with it
        self.interior = interior = Frame(canvas)
        interior_id = canvas.create_window(0, 0, window=interior,
                                        anchor=NW)

        # track changes to the canvas and frame width and sync them,
        # also updating the scrollbar
        def _configure_interior(event):
            # update the scrollbars to match the size of the inner frame
            size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
            canvas.config(scrollregion="0 0 %s %s" % size)
            if interior.winfo_reqwidth() != canvas.winfo_width():
                # update the canvas's width to fit the inner frame
                canvas.config(width=interior.winfo_reqwidth())

        interior.bind('<Configure>', _configure_interior)

        def _configure_canvas(event):
            if interior.winfo_reqwidth() != canvas.winfo_width():
                # update the inner frame's width to fill the canvas
                canvas.itemconfigure(interior_id, width=canvas.winfo_width())
        canvas.bind('<Configure>', _configure_canvas)

scframe = VerticalScrolledFrame2(root)
scframe.pack()
scframe.place(x = 1150,y = 40)
for value in cur.execute("SELECT name FROM tbl"):
    massive = list(value)
    def otpr_zadachi():
        win = Toplevel(root)
        win.geometry('700x550')
        win.resizable(False,False)
        win['bg'] = '#336B87'
        win.minsize(width=700, height= 550)
        win.title('Диалог с ' + massive[0])
         

        Send_btn = Button(win, text = '',padx=15,pady=12.5,bd=6,font=('Ubuntu',35))
        Send_btn_sms = Button(win, text = '➤',padx = 15,pady = 13.5,font = ('Ubuntu',35),bd = 6)
        Message_Text = Text(win,width = 37,height = 5,bg='white',fg='black',font = 50)
        frame = Frame(win)

        text = Text(frame, width=74, height=22)

        scroll = Scrollbar(frame, command=text.yview)
        scroll.pack(side=RIGHT, fill=Y)
         
        text.config(yscrollcommand=scroll.set)

        text.insert(INSERT,("text" + '\n') * 50)
        text.configure(state='disabled')
         
        text.pack(side=TOP)
         
        frame.pack(side=TOP)

        Send_btn.bind('<Button-1>',open_task)
        Send_btn.pack()
        Send_btn_sms.pack()
        Message_Text.pack()
        Send_btn.place(x = 580,y = 400)
        Send_btn_sms.place(x = 455, y = 400)
        Message_Text.place(x = 34,y = 400)



    btn = Button(scframe.interior, height=2, width=35, relief=FLAT, 
            bg='#336B87', fg='black', bd = 4,
            font="Dosis", text=massive[0],command = otpr_zadachi)

    #btn.bind('<Button-1>',otpr_zadachi)        

    btn.pack(padx=10, pady=5, side=TOP)

Above is a piece of the program (I’ll say right away that the idea with the class is not mine), and so Button with text from the database should be displayed there (which I did), but the otpr_zadachi command that opens a new window should display a window with data from the database, for example : win.title(Text from the button, (DB))
I hope I explained it well

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question