0
from tkinter import*
raiz=Tk()
raiz.title("Last Recently Used LRU")
raiz.resizable(1,1)
raiz.geometry("1080x720")
#-----------------------------------------
marcos=IntVar()
#-------------------------------------
label1=Label(raiz,text="Numero de Marcos:")
label1.place(x=260,y=100)
texto1=Entry(raiz,textvariable=marcos)
texto1.place(x=500,y=100)
s=StringVar()
label2_5=Label(raiz,text="*Introduce una cadena de numeros separados por espacios")
label2_5.place(x=260,y=200)
label2=Label(raiz,text="Cadena de Referencias:")
label2.place(x=260,y=250)
texto2=Entry(raiz,textvariable=s)
texto2.place(x=555,y=250)
def perro():
    PROC=IntVar()
    PROC = int(input())
    f, st, fallos, mf = [], [], 0, 'No'
    s = list(map(int, input().strip().split()))
for i in s:
    if i not in f:
        if len(f)<PROC:
            f.append(i)
            st.append(len(f)-1)
        else:
            ind = st.pop(0)
            f[ind] = i
            st.append(ind)
        mf = 'X'
        fallos += 1
    else:
        st.append(st.pop(st.index(f.index(i))))
    mf = '--'
    print("\n\n")
    print("   %d\t\t" % i, end='')
    for x in f:
        print(x, end=' ')
    for x in range(PROC - len(f)):
        print(' ', end=' ')
    print(" %s" % mf)
botonp=Button(raiz,text="Ejecutar",command=perro)


botonp.place(x=540,y=350)
raiz.mainloop()

line 33, in for i in s: TypeError: 'StringVar' object is not iterable

Ok here is the full code, i try to make a GUI with Tkinter but there's a problem, i don't know what to do with this error.

Any ideas how to fix?

2
  • What's your input? Commented Mar 1, 2019 at 18:05
  • Check the indent of line if i not in f: just after the line for i in s: If this is a typo in your post please edit it. Otherwise fix your code. Commented Mar 1, 2019 at 18:27

1 Answer 1

1

The name s is defined as a global variable of type StringVar with the statement:

s=StringVar()

so when you attempt to iterate over it with:

for i in s:

it produces the said exception since your StringVar object is not iterable.

The fact that you assigned s with a list inside the function perro does not help because the s variable that is assigned with a list is local to the perro function and is not at all the same s as the global variable.

You should make perro return the list and iterate over the returning value instead.

Change:

    s = list(map(int, input().strip().split()))
for i in s:

to:

    return list(map(int, input().strip().split()))
for i in perro():
Sign up to request clarification or add additional context in comments.

3 Comments

Where is there a variable called list in his code?
It's in "some other parts" of the OP's code as I mentioned. The OP did not post the code is full but it is certain that list has been assigned with other values in other parts of the code that are not posted here.
@GerardoSoto I've updated my answer accordingly then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.