2017-11-20 8 views
2

私はPython言語に精通していない新しい人です。私は試合のスコアを表示し、それは選手をランク付けするアプリに取り組んでいます。しかし、それはGUIが付属しているとき、私はこれまでに何をやったのかというと、女性用と女性用の2つのタップを作成しました。私は、テキストボックスを挿入するタブ内にすることができ、ボタンを押したときにテキストボックスがボタンにリンクされている場合は、ファイルの内容を表示するのだろうかと思います。コードの下python:txtboxにテキストボックスを挿入する必要があります

## this is the code 
from tkinter import * 
from tkinter import ttk 

root = Tk() 
root.geometry('500x500') 
note = ttk.Notebook(root) 

rows = 0 
while rows < 50: 
    root.rowconfigure(rows, weight=1) 
    root.columnconfigure(rows, weight=1) 
    rows += 1 

Button(root, text='Exit', command=root.destroy).grid(row=0, column=0) 

nb = ttk.Notebook(root) 
nb.grid(row=1, column=0, columnspan=50, rowspan=49, sticky='NESW') 

# Adds Men tab 
men = ttk.Frame(nb) 
nb.add(men, text='Men') 

# Adds Ladies tab 
ladies = ttk.Frame(nb) 
nb.add(ladies, text='Ladies') 

    enter code here 

root.mainloop() 
+0

何がファイルですか? – Nae

+0

4つの列を持つcsvファイル:「playerA、playerA sets、playerB、playerBは – Khalifa

答えて

1

ladiesタブの下にテキストウィジェットを作成し、Readボタンが押されたときに、CSVファイル、"theFile.csv"の内容は、テキストウィジェットに入れています。他のタブについても同様の部分を書くことができます。

import csv 
def put_file(): 
    with open('theFile.csv', newline='') as csvfile: 
     spamreader = csv.reader(csvfile, delimiter=',', quotechar='|') 

     for row in spamreader: 
      textL.insert("1.0", ', '.join(row)) 


textL = Text(ladies) 
textL.pack() 
Button(ladies, text="Read", command=put_file).pack() 
+0

に設定していただきありがとうございます。たとえば、特定の列を印刷して表示したい場合はもう1つうまく機能しました。隣に、私はtextL.insertにコードを追加する必要がありますか? – Khalifa

関連する問題