Home > Blockchain >  I want to make a benchmark app in python using Tkinter
I want to make a benchmark app in python using Tkinter

Time:01-22

I want it to show the user input but it is not showing. Please send help. I have tried code from multiple posts but no luck. I was able to make it show the 'selected' option but for no avail. Please help me

import tkinter as tk
from tkinter.ttk import *
app = tk.Tk()
# Functions and scripts
def OnSubmit():
    print(str(usrnme.get()))
    print(str(passw.get()))
    print(str(selected.get()))

app.title("Pymark: Landing Page")
app.geometry("600x600")
app.resizable(0, 0)
desc = """

PyMark is the first benchmark created using python's native GUI creator "Tkinter" and using hashes to rank performance.
The sofware is light and can run on older CPU's like i7-4510U (the processor I use) and does not require a lot of memory.
I am still open for constructive critisism and community feedback on my work as I am a beginner programmer.

IMPORTANT: PyMark can still experience bugs thus, pull requests are encouraged!

Please continue enjoying PyMark! 

"""

# Landing Page
lpframe = Frame(app)
mainheading = Label(lpframe, text="Welcome to PyMark!", font = ('Times New Roman', 20))
maindesc = Label(lpframe, text=f'{desc}', font = ('Times New Roman', 9))
lpframe.pack()
mainheading.pack(padx = 10, pady = 10)
maindesc.pack(padx = 10, pady = 10)
# Login Page
loginframe = Frame(app)
headerframe = Frame(loginframe, relief = 'groove')
loginheader = Label(headerframe, text='Login / Register: ', font = ('Times New Roman', 12))
usrnmelb = Label(loginframe, text = 'Username: ', font = ('Times New Roman', 9))
passlb = Label(loginframe, text = 'Password: ', font = ('Times New Roman', 9))
selected = tk.StringVar()
register = Radiobutton(loginframe, text='Register', value='reg', variable=selected)
login = Radiobutton(loginframe, text='Login', value='log', variable=selected)
submitbtn = Button(loginframe, text = 'Submit', command=OnSubmit)
usrnmeentr = Entry(loginframe)
passentr = Entry(loginframe)
loginframe.pack()
headerframe.pack(padx = 20, pady = 20)
loginheader.pack(padx = 20, pady = 20)
usrnmelb.pack()
usrnmeentr.pack()
passlb.pack()
passentr.pack()
register.pack()
login.pack()
submitbtn.pack(padx = 10, pady = 10)
usrnme = tk.StringVar()
passw = tk.StringVar()
usrnmeentr.focus()
app.mainloop()

I expected it to return the username, password and the selected option but it only told the selected option and nothing else.

CodePudding user response:

The OnSubmit() function does not get the correct inputs to print. Get the entryfields content with the method .get(). In your case the OnSubmit() function should look like this:

def OnSubmit():
    print(str(usrnmeentr.get())) #usrnme.get() was not the name of the entry box
    print(str(passentr.get()))
    print(str(selected.get()))

CodePudding user response:

You must link your Entry to Stringvar(), not your radio buttons

import tkinter as tk

app = tk.Tk()
app.geometry('300x300')


# Functions and scripts
def OnSubmit():
    print(var.get())


var = tk.StringVar()
entry = tk.Entry(app, textvariable=var)
entry.pack()

bt = tk.Button(app, text='Show', command=OnSubmit)
bt.pack()
app.mainloop()

Example Gif

  • Related