Python Forum
Displaying output in GUI ( Tkinter)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying output in GUI ( Tkinter)
#5
I did use the print when I was in Python.
Do i need to replace the word "print"
I am very very new.

rom tkinter import *

window = Tk()
window.title("Welcome to Dr.G app")
window.geometry('700x500')
window.configure(background = "#49a")
my_entries = []
def create_balanced_round_robin(players):
    """ Create a schedule for the players in the list and return it"""
    s = []
    if len(players) % 2 == 1: players = players + ["BYE"]
    # manipulate map (array of indexes for list) instead of list itself
    n = len(players)
    print(n)
    map = list(range(n))
    mid = n // 2
    for i in range(n-1):
        l1 = map[:mid]
        l2 = map[mid:]
        l2.reverse()
        round = []
        for j in range(mid):
            t1 = players[l1[j]]
            t2 = players[l2[j]]
            if j == 0 and i % 2 == 1:
                # flip the first match only, every other round
                # (this is because the first match always involves the last player in the list)
                round.append((t2, t1))
            else:
                round.append((t1, t2))

        s.append(round)
        # rotate list by n/2, leaving last element at the end
        map = map[mid:-1] + map[:mid] + map[-1:]
    return s

def something():
    player_list = []
    entry_list = ""
    for entries in my_entries:
        if str(entries.get()) != "":
             player_list.append(str(entries.get()))
             entry_list = entry_list + str(entries.get()) + "\n"

    #The var entryvar contains the text widget content
    entryvar = player_list
    player_list.delete(1.0,tk.END)
    player_list.insert(tk.END)
    my_label.config(text=entryvar)
    my_label.pack

    schedule = create_balanced_round_robin(player_list)
    print("\n".join(['{} vs. {}'.format(m[0], m[1]) for round in schedule for m in round]))

#row loop
for y in range(5):
     #column loop
     for x in range(5):
        my_entry = Entry(window)
        my_entry.grid(row=y, column=x, pady=20, padx=5)
        my_entries.append(my_entry)
my_button = Button(window, text="Click Me", command=something)
my_button.grid(row=6, column=0, pady=20)
my_label = Label(window,
                 text=" ",
                 font=("Arial Bold", 15))
my_label.grid(row=7, column=0, pady=20)
window.mainloop()

The va entry var....my label pack was added for the GUI.
Reply


Messages In This Thread
RE: Displaying output in GUI ( Tkinter) - by buran - Sep-28-2020, 10:36 AM
RE: Displaying output in GUI ( Tkinter) - by buran - Sep-28-2020, 10:48 AM
RE: Displaying output in GUI ( Tkinter) - by Zouloutamtam - Sep-28-2020, 10:55 AM
RE: Displaying output in GUI ( Tkinter) - by buran - Sep-28-2020, 11:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter | entry output. Sap2ch 1 2,013 Sep-25-2021, 12:38 AM
Last Post: Yoriz
  [Tkinter] acceleration of data output in treeview tkinter Vladimir1984 4 4,236 Nov-21-2020, 03:43 PM
Last Post: Vladimir1984
  Active tkinter text output during loop dvanommen 2 10,810 Oct-18-2019, 02:23 PM
Last Post: dvanommen
  sQlite3 output to tkinter treeview - how do I set / increase width of the output? dewijones67 5 6,681 Jan-23-2019, 08:45 AM
Last Post: Larz60+
  [Tkinter] tkinter - unexpected output - don't know how func is triggered before calling omm 8 4,508 Dec-11-2018, 08:09 PM
Last Post: Gribouillis
  How to format a list when displaying in a tkinter Listbox nortski 3 9,630 Apr-03-2018, 02:31 AM
Last Post: Larz60+
  [Tkinter] Tkinter widgets driving Arduino uno output pins woodcncwnc 3 4,588 Jan-29-2018, 08:21 PM
Last Post: woodcncwnc

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020