Build a Tkinter GUI Application to Fetch and Display User Data in Python

Here is a simple Tkinter GUI application to fetch and display user data in Python, perfect for beginners learning Python GUI programming.

gui tkinter fetch

Tkinter code

import tkinter as tk
from functools import partial

FIELDS = [
    'State', 'City',
    'Customer 1', 'Sales 1',
    'Customer 2', 'Sales 2',
    'Customer 3', 'Sales 3',
    'Customer 4', 'Sales 4'
]

def fetch(entries):
    print(entries)
    for field, text in entries:
       print('%s: "%s"' % (field, text.get())) 


def makeform_grid(window, fields):
    entries=[]
    for i, field in enumerate(fields):
        row, column = divmod(i, 2)
        tk.Label(window, text=field).grid(row=row, column=column*2)
        entry = tk.Entry(window)
        entry.grid(row=row, column=column*2+1)
        entries.append((field, entry))
    return entries


def main():
    window = tk.Tk()
    entries = makeform_grid(window, FIELDS)
    tk.Button(window, text="Fetch", command=partial(fetch, entries)).grid(row=11,column=0)
    tk.Button(window, text="Quit", command=window.destroy).grid(row=12,column=0,pady=20)
    window.mainloop()

if __name__ == '__main__':
    main()

In this example, the GUI allows users to input State, City, customer details, and sales data through interactive entry fields for easy data visualization.

See also  Creating Pop-up Windows in Tkinter

Feel free to extend and adapt to your needs.