473,387 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Principiante in cerca di spiegazione!

Ciao a tutti,
premetto a tutti che stò imparando proprio adesso a studiare python ed
ho il seguente problema ... questo script copiato pari pari da un
tutorial mi ridà un'errore che non capisco.. questo è il codice:

from Tkinter import * # importo il modulo

# costruisco una mia classe che gestisce la finestra
class Application(Frame):

# metodo che scrive un messaggio a video
def scrivi_messaggio(self):
self.mess["text"] = "Ciao a tutti!",

# metodo che pulisce il messaggio a video
def cancella_messaggio(self):
self.mess["text"] = "",

# metodo costruttore che crea gli oggetti grafici
def __init__(self, master=None):
f = Frame(master)
f.pack()

# crea il bottone di uscita (di colore rosso)
self.esci = Button(f)
self.esci["text"] = "QUIT"
self.esci["fg"] = "red"
self.esci["command"] = f.quit
self.esci.pack({"side": "left"})

# crea il bottone che permette di scrivere il messaggio
self.butt_mess = Button(f)
self.butt_mess["text"] = "Scrivi",
self.butt_mess["command"] = self.scrivi_messaggio
self.butt_mess.pack({"side": "left"})

# crea il bottone che permette di pulire il messaggio
self.butt_canc_mess = Button(f)
self.butt_canc_mess["text"] = "Cancella",
self.butt_canc_mess["command"] = self.cancella_messaggio
self.butt_canc_mess.pack({"side": "left"})

# crea l'oggetto grafico che contiene il messaggio
self.mess = Message(f)
self.mess["text"] = "",
self.mess.pack({"side": "left"})
# corpo principale del programma
finestra = Tk()
app = Application(finestra)
finestra.mainloop()

e mi ritorna un'errore come:

Traceback (most recent call last):
File "C:/Python23/tests/tkinter.py", line 4, in -toplevel-
class Application(Frame):
File "C:/Python23/tests/tkinter.py", line 20, in Application
self.esci = Button(f)
NameError: name 'f' is not defined

?? Eppure la var f è definita nell' _INIT_

qualcuno mi sà spiegare perchè?

Grazie in anticipo!

Augusto
Jul 18 '05 #1
3 1474
Augusto wrote:
Ciao a tutti,
premetto a tutti che stò imparando proprio adesso a studiare python ed
ho il seguente problema ... questo script copiato pari pari da un
tutorial mi ridà un'errore che non capisco.. questo è il codice:

from Tkinter import * # importo il modulo

# costruisco una mia classe che gestisce la finestra
class Application(Frame):

# metodo che scrive un messaggio a video
def scrivi_messaggio(self):
self.mess["text"] = "Ciao a tutti!",

# metodo che pulisce il messaggio a video
def cancella_messaggio(self):
self.mess["text"] = "",

# metodo costruttore che crea gli oggetti grafici
def __init__(self, master=None):
f = Frame(master)
f.pack()
You may be mixing tabs and spaces. Try to use *only* spaces.
Every thing from here...
# crea il bottone di uscita (di colore rosso)
self.esci = Button(f)
self.esci["text"] = "QUIT"
self.esci["fg"] = "red"
self.esci["command"] = f.quit
self.esci.pack({"side": "left"})

# crea il bottone che permette di scrivere il messaggio
self.butt_mess = Button(f)
self.butt_mess["text"] = "Scrivi",
self.butt_mess["command"] = self.scrivi_messaggio
self.butt_mess.pack({"side": "left"})

# crea il bottone che permette di pulire il messaggio
self.butt_canc_mess = Button(f)
self.butt_canc_mess["text"] = "Cancella",
self.butt_canc_mess["command"] = self.cancella_messaggio
self.butt_canc_mess.pack({"side": "left"})

# crea l'oggetto grafico che contiene il messaggio
self.mess = Message(f)
self.mess["text"] = "",
self.mess.pack({"side": "left"})
.... to here must be indented to the same level as the two first lines in
the body of the __init__() method
# corpo principale del programma
finestra = Tk()
app = Application(finestra)
finestra.mainloop()

e mi ritorna un'errore come:

Traceback (most recent call last):
File "C:/Python23/tests/tkinter.py", line 4, in -toplevel-
class Application(Frame):
File "C:/Python23/tests/tkinter.py", line 20, in Application
self.esci = Button(f)
NameError: name 'f' is not defined
f is only known inside the body of __init__()

?? Eppure la var f è definita nell' _INIT_

qualcuno mi sà spiegare perchè?

Grazie in anticipo!

Augusto


Remember: whitespace *is* significant in Python.

Peter

PS: Try to post in english, nobody will care for occasional mistakes.

Jul 18 '05 #2
On Wednesday 11 February 2004 4:43 pm, Augusto wrote:
Ciao a tutti,
premetto a tutti che stò imparando proprio adesso a studiare python ed
ho il seguente problema ... questo script copiato pari pari da un
tutorial mi ridà un'errore che non capisco.. questo è il codice:

from Tkinter import * # importo il modulo

# costruisco una mia classe che gestisce la finestra
class Application(Frame):

# metodo che scrive un messaggio a video
def scrivi_messaggio(self):
self.mess["text"] = "Ciao a tutti!",

# metodo che pulisce il messaggio a video
def cancella_messaggio(self):
self.mess["text"] = "",

# metodo costruttore che crea gli oggetti grafici
def __init__(self, master=None):
f = Frame(master)
f.pack()

# crea il bottone di uscita (di colore rosso)
self.esci = Button(f)
self.esci["text"] = "QUIT"
self.esci["fg"] = "red"
self.esci["command"] = f.quit
self.esci.pack({"side": "left"})

# crea il bottone che permette di scrivere il messaggio
self.butt_mess = Button(f)
self.butt_mess["text"] = "Scrivi",
self.butt_mess["command"] = self.scrivi_messaggio
self.butt_mess.pack({"side": "left"})

# crea il bottone che permette di pulire il messaggio
self.butt_canc_mess = Button(f)
self.butt_canc_mess["text"] = "Cancella",
self.butt_canc_mess["command"] = self.cancella_messaggio
self.butt_canc_mess.pack({"side": "left"})

# crea l'oggetto grafico che contiene il messaggio
self.mess = Message(f)
self.mess["text"] = "",
self.mess.pack({"side": "left"})
# corpo principale del programma
finestra = Tk()
app = Application(finestra)
finestra.mainloop()

e mi ritorna un'errore come:

Traceback (most recent call last):
File "C:/Python23/tests/tkinter.py", line 4, in -toplevel-
class Application(Frame):
File "C:/Python23/tests/tkinter.py", line 20, in Application
self.esci = Button(f)
NameError: name 'f' is not defined

?? Eppure la var f è definita nell' _INIT_

qualcuno mi sà spiegare perchè?

Grazie in anticipo!

Augusto


f is indeed defined in __init__ and is therefore local to __init__. The name
is not available outside that method. I think that your problem may be that
the code following "f.pack()" to the end of the class definition is meant
also to be part of the __init__ function. Try indenting it all to be level
with "f.pack()".

James
--
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
http://sourceforge.net/projects/mailmanager/
Jul 18 '05 #3
All right.. Thanks! Now it's ok..

Python rulez! bye!
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: qwweeeit | last post by:
Hi all, Elliot Temple on the 1 June wrote: > How do I make Python press a button on a webpage? I looked at > urllib, but I only see how to open a URL with that. I searched > google but no...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
0
by: sara | last post by:
Hi, I have a little problem. This is the code one of my page. My problem is that the function "leggi1" is not executed. Where do I make a mistake? <%@ Page Language="VB" AutoEventWireup="false"...
0
by: sara | last post by:
Hi, this is the code of a (2005) asp page. I've a problem during the execution. When I click on "Leggi" button the javascript function "leggi1" is not done! Why? Someone can I helm me, please! ...
19
by: ash | last post by:
hi friends, i have some questions whch is in my last year question papers.i need some help to get logic of these questions. 1) write a C function, that takes two strings as arguments and...
1
by: seba | last post by:
Ciao a tutti, vorrei sviluppare in C++ sotto Fedora Core 5. Ho dei problemi con ECLIPSE, quindi chiedo se qualcuno puo' consigliarmi qualche buon tool di sviluppo. CIAO!
0
by: molcaleviATyahoogroupsDOTcom | last post by:
B " H _ KO mafia ! Global Democracy ARTSENU & Fusione Fredda = TRIVOLUZIONE W post OPEC ! ! ! e' SAUDITA - Bin Laden la cosi' detta '' mafia ebraica CFR globalmafia ILLUMINATI '' ....
1
by: diaboliko80 | last post by:
Salve a tutti. Ho un problema con IE7. Ho implementato una pagina .asp che tramite tecnologia AJAX mi crea una serie di select nidificate (il classico esempio delle Regioni-Province --scelgo...
0
by: molcaleviATyahoogroupsDOTcom | last post by:
KO mafia CFR ILLUMINATI ! Global Democracy TRIVOLUZIONE ARTSENU COLD FUSION W post OPEC ! B '' H _ KO mafia ! Global Democracy ARTSENU & Fusione Fredda = TRIVOLUZIONE W post OPEC ! ! !
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.