Hi all!
I have a problem with a cycle while and a value list.
How to dynamicize them without knowing what are the values in a list?
And how do I recall a function ( call in my ex.) with the appropriate value?
Thanks
Hud
import tkHyperlinkManager #external lib
from Tkinter import *
i = 0
li_all = [0, 1, 2, 3, 4] #dynamic list
root = Tk()
root.title("Test")
text = Text(root)
text.pack()
hyperlink = tkHyperlinkManager.HyperlinkManager(text)
def call(x):
print x
while i <= 3:
if i == 0:
text.insert(INSERT, "this is a ")
text.insert(INSERT, "link test", hyperlink.add(lambda: call(li_all[0])))
text.insert(INSERT, "\n\n")
if i == 1:
text.insert(INSERT, "this is a ")
text.insert(INSERT, "link test", hyperlink.add(lambda: call(li_all[1])))
text.insert(INSERT, "\n\n")
if i == 2:
text.insert(INSERT, "this is a ")
text.insert(INSERT, "link test", hyperlink.add(lambda: call(li_all[2])))
text.insert(INSERT, "\n\n")
if i == 3:
text.insert(INSERT, "this is a ")
text.insert(INSERT, "link test", hyperlink.add(lambda: call(li_all[3])))
text.insert(INSERT, "\n\n")
print li_all[i]
i = i + 1
mainloop()
Second ex. but the output result remains 4....
import tkHyperlinkManager #external lib
from Tkinter import *
i = 0
li_all = [0, 1, 2, 3, 4] #dynamic list
root = Tk()
root.title("Test")
text = Text(root)
text.pack()
hyperlink = tkHyperlinkManager.HyperlinkManager(text)
def call(x):
print x
while i <= 3:
text.insert(INSERT, "this is a ")
text.insert(INSERT, "link test", hyperlink.add(lambda: call(li_all[i])))
text.insert(INSERT, "\n\n")
print li_all[i]
i = i + 1
mainloop()