Python Forum
Displaying output in GUI ( Tkinter)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying output in GUI ( Tkinter)
#1
Hi everyone
I am new to "programing".
I am experiencing some problems to display my output data on Tkinter. i have been reading a lot. but i am not geting there.
I am doing a round robin tournament and it is printed out in Python. (That part is working)
I would it to be printed in Tkinter.
Thanks.
Reply
#2
In GUI development you don't print (i.e. to console/or whatever stdout is). You display information using respective widgets
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
First of all thanks for the quick response.
I did introduce widgets for my outputs. For some reasons, the code does not work.
I can show you the code if you want.
Reply
#4
(Sep-28-2020, 10:44 AM)Zouloutamtam Wrote: For some reasons, the code does not work.
I can show you the code if you want.
that would be a good start. Post your code in python tags, full traceback if you get any - in error tags.
See BBcode help for more info.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#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
#6
it's not about replacing print. You must use widgets, for exaple Label, to display information. There are other widgets, that may be more suitable, depending on what king of information you want to display

and by the way, you are still in python :-)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
If line 45 - 50 are removed. you should get a scheduled tournament after putting some names. A vs B, F vs C...
I would like to get this output in Tkinker. There comes lines 45 -50. In my layman mind i get what i am trying to do. Buyt i am using the wrong code. I need to use widget and label.

Can you please tell me hoe you get the numbers primted on the side. I have been trying. i am not getting it.
Reply
#8
All sorted. I have put the outputs to labels.
from 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"
#output
    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)
    my_label.config(text="\n".join(['{} vs. {}'.format(m[0], m[1]) for round in schedule for m in round]))

#Input
#row loop
for y in range(5):
     #column loopetes
     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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter | entry output. Sap2ch 1 209 Sep-25-2021, 12:38 AM
Last Post: Yoriz
  [Tkinter] acceleration of data output in treeview tkinter Vladimir1984 4 1,170 Nov-21-2020, 03:43 PM
Last Post: Vladimir1984
  Active tkinter text output during loop dvanommen 2 6,288 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 4,056 Jan-23-2019, 08:45 AM
Last Post: Larz60+
  [Tkinter] tkinter - unexpected output - don't know how func is triggered before calling omm 8 2,143 Dec-11-2018, 08:09 PM
Last Post: Gribouillis
  How to format a list when displaying in a tkinter Listbox nortski 3 7,098 Apr-03-2018, 02:31 AM
Last Post: Larz60+
  [Tkinter] Tkinter widgets driving Arduino uno output pins woodcncwnc 3 2,689 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