0

I have a menu button in a GUI I am making that displays a popup containing a CSV file, using pd.read_csv through pandas. However, there is a lot of data, and when the popup is displayed, pandas cuts off a lot of the data, only displaying the data in the beginning and in the end of the file.

I want to be able to scroll through all the data in my popup window. Any suggestions?

Here is the code for the popup command:

def popuptable():
    popup = tk.Tk()
    popup.wm_title("!")
    label = ttk.Label(popup, text=(pd.read_csv('NameofCSVFile.csv')), font=NORM_FONT)
    label.pack(side="top", fill="x", pady=10)
    popup.mainloop()
6
  • 1
    BTW: Tkinter should use only one Tk() - to create second window use Toplevel(). And it needs only one mainloop(). If you use second mainloop() it can behave strange. Commented Jan 12, 2017 at 15:46
  • to scroll element you will have to use Canvas() with this element and scroll canvas. Or use ScrolledText() which can be scrolled. Commented Jan 12, 2017 at 15:49
  • @furas can i use Canvas() within my popup? Commented Jan 12, 2017 at 15:51
  • Canvas is normal widget (like Label or Button) so you can use it in Tk/Toplevel but creating scrolled Canvas sometimes makes problem - you can find example on SO. Commented Jan 12, 2017 at 15:53
  • scrollbar with Text or Canvas Commented Jan 12, 2017 at 15:56

1 Answer 1

1

I give you an example of how to do a scrollable text widget that looks like a label. I put it in the main window for this example, but you just have to replace root by a toplevel to adapt it to your case.

from tkinter import Tk, Text, Scrollbar

root = Tk()
# only the column containing the text is resized when the window size changes:
root.columnconfigure(0, weight=1) 
# resize row 0 height when the window is resized
root.rowconfigure(0, weight=1)

txt = Text(root)
txt.grid(row=0, column=0, sticky="eswn")

scroll_y = Scrollbar(root, orient="vertical", command=txt.yview)
scroll_y.grid(row=0, column=1, sticky="ns")
# bind txt to scrollbar
txt.configure(yscrollcommand=scroll_y.set)

very_long_list = "\n".join([str(i) for i in range(100)])

txt.insert("1.0", very_long_list)
# make the text look like a label
txt.configure(state="disabled", relief="flat", bg=root.cget("bg"))

root.mainloop()

Screenshot:

screenshot

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.