0

it's easy, i have to replace the Label "risdado" in appdadi with the Label "rispodado" from dado6 function.

but when i click on the button "tira6" it gives me
NameError: global name 'risdado' is not defined

i've allready used this system in another case and it runs fine, the difference in that case was that the target (where to replace the label) was not a function-generated window.
i'm a very beginner so, if is only a careless mistake, sorry.
ask for more detail.

from Tkinter import *
from tkMessageBox import *
from random import *

#DICE 6
#---------
def dado6():
    risdado.pack_forget()
    a=randint(1,6)
    rispodado=Label(appdadi, text=a, font=(Helvetica, 20)).pack()


#DICE APP
#-------
def dadi():
    appdadi=Tk()
    appdadi.resizable(0,0)
    dicepace1=Label(appdadi, bg="#009E71", width=40).pack(fill=X)
    labdadi=Label(appdadi, text="- D & D - DICE -", font=("Helvetica", 12), fg="White", bg="#009E71").pack(fill=X)
    dicespace2=Label(appdadi, bg="#009E71").pack(fill=X)
    dicespace3=Label(appdadi,).pack()

    tira6=Button(appdadi, text="dado da 6", command=dado6).pack()
    tira21=Button(appdadi, text="dado da 21").pack()
    tira100=Button(appdadi, text="dado da 100").pack()

    risdado=Label(appdadi, text="--------")
    risdado.pack(anchor=S)
HANZO
  • 55
  • 1
  • 1
  • 8
  • Are you wanting to replace the actual label widget, or just the text displayed on the widget? – Bryan Oakley Mar 01 '15 at 23:55
  • all the widget, but in the same position. as you can see the new label got a different name. but, if possible, replace only the text (that would be the goal). – HANZO Mar 01 '15 at 23:58
  • @HANZO You can change the text of a label by setting its `text` property using the `config` method, if that's what you want: `my_label.config(text="new_text")` – nbro Mar 02 '15 at 00:14
  • it giving me the same problem: **NameError**: global name 'risdado' is not defined – HANZO Mar 02 '15 at 00:24
  • `risdado` is a local variable. Are you aware of what a local variable is, and how it is different from a global variable? You might want to read http://stackoverflow.com/questions/291978/short-description-of-python-scoping-rules – Bryan Oakley Mar 02 '15 at 12:01
  • i setted **risdado** and **appdadi** as global variables, but now with the risdado.config(appdadi, text=value to replace), system it giving me **AttributeError: 'int' object has no attribute 'config'** – HANZO Mar 02 '15 at 14:48

0 Answers0