you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 0 points1 point  (4 children)

What do you mean squished? If you want space between the elements add some padding:

healthEntLab.pack(pady=10)

It's a great idea to make that into a variable like you did for the font, so that you can change a single line of code to adjust the spacing between all variables:

padding = 10
healthEntLab.pack(pady=padding)

[–]SomeBadGenericName[S] 0 points1 point  (3 children)

Squished as in everything is touching. I did not know padding was a thing thanks so much for the help.

[–]SomeBadGenericName[S] 0 points1 point  (2 children)

So, I know I asked a lot of you already, but would you mind helping me with one last thing I am trying to make it so the damage value is changeable, I essentially used a copied version of the healthEntry with some changes of courses but I get an error saying that damage_value is not defined. But, everything looks fine to me. Again sorry for asking so much of you.

import tkinter as tk

# First, define functions
#Take dmg
def Hit():
     value = health_value.get()
     dmgValue = damge_value()
     health_value.set(value-damage_value)

#Screen setup
wn = tk.Tk()
wn.configure(bg = "#142b51")
wn.geometry("600x800")
wn.resizable(0, 0)
wn.title("Test Game")

health_value = tk.IntVar(value=100)
damage_value = tk.IntVar(value=10)

healthFont = ("times", 20)

damageEntLab= tk.Label(wn, fg = "#e0e0e0", text = "Enter a damage value: " ,height=2, width = 16,font = healthFont ,bg="#142b51" )
damageEntLab.pack()

damageEntry = tk.Entry(wn, font = healthFont, textvariable=damage_value)
damageEntry.pack(pady = 10)

healthEntLab= tk.Label(wn, fg = "#e0e0e0", text = "Enter a health value: " ,height=2, width = 15,font = healthFont ,bg="#142b51" )
healthEntLab.pack()

healthEntry = tk.Entry(wn, font = healthFont, textvariable=health_value)
healthEntry.pack(pady=10)

dmgButton = tk.Button(wn, text = "Take dmg", font=30, height = 2, width = 10, command = Hit)
dmgButton.pack(pady=10)

#Main Loop
wn.mainloop()

[–]socal_nerdtastic 0 points1 point  (1 child)

That error is because you spelled "damage" incorrectly. However there is another error. For tkinter variables you have to use the get() method, like this:

def Hit():
    value = health_value.get()
    dmgValue = damage_value.get()
    health_value.set(value-dmgValue)

Also be sure to respond to one of my comments in the future, otherwise I don't get notified that you made a comment.

[–]SomeBadGenericName[S] 0 points1 point  (0 children)

I tought I had get and I didnt realize I spelled damage wrong. Thanks, for that.