@Fizl

Как выводить Button, в каждом из которых есть данные БД?

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)

Сверху приведен кусок программы(сразу скажу, что идея с классом не моя), так вот там должны выводиться Button с текстом из БД(что я сделал), но вот команда otpr_zadachi, открывающая новое окно, должна выводить окно с данными из бд, допустим : win.title(Текст с кнопки,(БД))
Надеюсь нормально объяснил
  • Вопрос задан
  • 87 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы