Home > OS >  Need help creating a GUI with Tkinter in python
Need help creating a GUI with Tkinter in python

Time:04-25

I am trying to make a Pokedex using pokeapi, and to make that I need a GUI, i am trying to make it look something like this: enter image description here

I don't really know how to add the "???" marks under the values of "name and "HP" so far my code looks like this:

from tkinter import *
from pokeapi import *

#create a new GUI window
window = Tk()
window.title("Pokedex")

#a label containing the instructions
lblInstructions = Label(window,text="Enter a number between 1 and 718:")
lblInstructions.pack()

#an 'entry' textbox for typing in the pokemon number
txtPokemonNo = Entry(window)
txtPokemonNo.pack()

#a button that will get the info for a pokemon
btnGetInfo = Button(window,text="Get Data!")
btnGetInfo.pack()

#labels for the pokemon name
lblNameText = Label(window,text="Name:")
lblNameText.pack()
lblNameValue = Label(window,text="???")
lblNameValue = Label(window,text="HP")
lblNameValue.pack()

window.mainloop()

I need to add the other values with the varibles (the question marks) can anyone help with that?

CodePudding user response:

You need to add a callback to the button.

CodePudding user response:

2 errors actually:

  1. You forgot to pack the label with "???"
  2. The "???" label and HP name label have the same variable name. Code:
from tkinter import *
from pokeapi import *

#create a new GUI window
window = Tk()
window.title("Pokedex")

#a label containing the instructions
lblInstructions = Label(window,text="Enter a number between 1 and 718:")
lblInstructions.pack()

#an 'entry' textbox for typing in the pokemon number
txtPokemonNo = Entry(window)
txtPokemonNo.pack()

#a button that will get the info for a pokemon
btnGetInfo = Button(window,text="Get Data!")
btnGetInfo.pack()

#labels for the pokemon name
lblNameText = Label(window,text="Name:")
lblNameText.pack()
lblNameValue = Label(window,text="???")
lblNameValue.pack()
lblHPName = Label(window,text="HP")
lblHPName.pack()
lblHPValue = Label(window,text="0")
lblHPValue.pack()
# Continue like this

window.mainloop()
  • Related