Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63856
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Tkinter GUI Error |
| Date | 2014-01-13 20:03 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <lb1dae$tbm$1@dont-email.me> (permalink) |
| References | <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> |
Am 13.01.14 19:49, schrieb fluttershy363@gmail.com:
>
> Inside the function is where I am having the problem, I am trying to get it to delete the label so that it may then replace it with a shorter text.
> Here is the full code:
>
>
>
>
> from tkinter import *
> import random
> main = Tk()
> main.title("Crack the Code")
>
> def check1():
> entry = entry1var.get()
> if entry == num1:
> labelent1.destroy()
> labelent1 = Label(main, text="Correct!",fg="green").grid(row = 0, column = 3)
This is the wrong way to do it. Yes, in principle you could remove the
label and put a new one there; but it's much better to just change the
text of it by means of either
labelent1.configure(text="New text ")
or by linking a variable with the label variable at the setup time
somestringvar = StringVar("initial text")
Label(main, textvariable=somestringvar)
and then change that variable
somestringvar.set("New text")
Both of these don't solve the error, though; it has nothing to do with
Tk, you just did not make labelent1 global. However, I strongly advise
to use an object for the entire window, where you make this labelent1 an
instance variable (put into self).
Christian
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Tkinter GUI Error fluttershy363@gmail.com - 2014-01-13 10:49 -0800
Re: Tkinter GUI Error Lewis Wood <fluttershy363@gmail.com> - 2014-01-13 10:51 -0800
Re: Tkinter GUI Error Christian Gollwitzer <auriocus@gmx.de> - 2014-01-13 20:03 +0100
Re: Tkinter GUI Error Lewis Wood <fluttershy363@gmail.com> - 2014-01-13 11:21 -0800
Re: Tkinter GUI Error Peter Otten <__peter__@web.de> - 2014-01-13 20:36 +0100
Re: Tkinter GUI Error Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-13 20:39 -0500
Re: Tkinter GUI Error Rick Johnson <rantingrickjohnson@gmail.com> - 2014-01-13 18:47 -0800
Re: Tkinter GUI Error Chris Angelico <rosuav@gmail.com> - 2014-01-14 14:12 +1100
Re: Tkinter GUI Error Lewis Wood <fluttershy363@gmail.com> - 2014-01-14 11:11 -0800
Re: Tkinter GUI Error Lewis Wood <fluttershy363@gmail.com> - 2014-01-14 13:27 -0800
Re: Tkinter GUI Error Christian Gollwitzer <auriocus@gmx.de> - 2014-01-14 22:33 +0100
csiph-web