Reputation: 19
I am a new guy who is not familiar with python language. I am working on app that shows a match scores and it ranks the players. However, I am stuck when it comes with GUI, what I've done so far I created two taps one for the ladies and one for men. I am wondering if I could within the tabs to insert a textbox and the textbox is linked to a button when I press button it shows the file's content.
## 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()
Upvotes: 2
Views: 285
Reputation: 15345
Below code creates a Text widget under ladies
tab and when Read
button is pressed the contents of a csv file, "theFile.csv"
is put into the Text widget. A similar piece can be written for the other tab as well.
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()
Upvotes: 1