2017-01-12 13 views
0

GUIにメニューボタンがあります。これは、pandasからpd.read_csvを使ってCSVファイルを含むポップアップを表示しています。しかし、多くのデータがあり、ポップアップが表示されると、パンダは多くのデータをカットし、ファイルの先頭と末尾にのみデータを表示します。Tkinterのポップアップテーブルにスクロールバーを追加します。

ポップアップウィンドウ内のすべてのデータをスクロールできます。助言がありますか?ここで

がポップアップコマンドのコードです:

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() 
+1

BTW: 'Tkinter'は使用すべき唯一の' Tkの() ' - 2番目のウィンドウの使用 'トップレベル()'を作成します。そして、 'mainloop()'だけが必要です。 2番目の 'mainloop()'を使うと変な動作をすることができます。 – furas

+0

要素をスクロールするには、この要素とスクロールキャンバスで 'Canvas()'を使用する必要があります。または、スクロール可能な[ScrolledText()](https://docs.python.org/3.5/library/tkinter.scrolledtext.html#module-tkinter.scrolledtext)を使用してください。 – furas

+0

@furasポップアップ内でCanvas()を使用できますか? –

答えて

0

私はあなたのラベルのように見えるスクロール可能なテキストウィジェットを行う方法の例を与えます。私はこの例のメインウィンドウに入れましたが、あなたのケースに合わせてrootをトップレベルに置き換えてください。

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

関連する問題