The text does not move with the scroll bar as if the text is not attached to it. In the pop-up window, the middle of the text is visible, but not the beginning and the scroll bar moves, and the text is in place. I just can not figure out the scroll bar.

def window_open(label_1): # Всплывающее окно toplevel = Toplevel() toplevel.title("Химические элементы таблицы Менделеева") toplevel.geometry("500x500+600+200") label_new = Label(toplevel, text=label_1, height=0, width=100, wraplength=500) label_1 = Text(toplevel) scroll = Scrollbar(toplevel, orient='vertical') label_1.configure(yscrollcommand=scroll.set) scroll['command'] = label_1.yview label_1.pack scroll.pack(side=RIGHT, fill=Y) label_new.pack() 
  1. How to make the text open from the beginning, not from the middle?
  2. How does the scrollbar snap to text?
  3. Where can I read about Scrollbar?
  • And what text do you think should be scrolled? the one that you type in Label or the one in which you enter the Text data yourself? because you add some data in the Label and scroll the data in the Text - Twiss
  • I need to scroll the data of 'label_1', I don’t understand how to do it - max ser
  • Label does not support scrolling. But you can put it inside the Canvas - it supports. - insolor
  • @insolor, as if it were not strange, but label_1 has Text ) - Twiss
  • @Twiss, really, did not pay attention) - insolor 2:43 pm

1 answer 1

you yourself label_1 not displayed in Toplevel you forgot to add the pack() function brackets slightly corrected your code for more correctness :)

About ScrollBar you can read here

 from tkinter import * def window_open(label_1): # Всплывающее окно toplevel = Toplevel() toplevel.title("Химические элементы таблицы Менделеева") toplevel.geometry("500x500+600+200") label = Label(toplevel, text="Какой то текст", height=0, width=100, wraplength=500) label.pack() scroll = Scrollbar(toplevel, orient='vertical') scroll.pack(side=RIGHT, fill=Y) text = Text(toplevel) text.insert(END, label_1 * 5) text.configure(yscrollcommand=scroll.set) text.pack(side=LEFT, fill=BOTH) a = """def window_open(label_1): # Всплывающее окно toplevel = Toplevel() toplevel.title("Химические элементы таблицы Менделеева") toplevel.geometry("500x500+600+200") label_new = Label(toplevel, text=label_1, height=0, width=100, wraplength=500) label_1 = Text(toplevel) scroll = Scrollbar(toplevel, orient='vertical') label_1.configure(yscrollcommand=scroll.set) scroll['command'] = label_1.yview label_1.pack scroll.pack(side=RIGHT, fill=Y) label_new.pack() """ root = Tk() but = Button(root, text="Нажми", command=lambda: window_open(a)) but.pack() root.mainloop() 

enter image description here

  • Thank you very much for the help. I myself have not figured it out so far, now I will add to my program. This is my first program. [ github.com/maxim58r/Chemistry/commits/master] here is the link to the program itself, the truth still did not work - max ser