Faqts : Business : Programming : Shopping For You : Python : Tkinter

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 5 people (80%) answered Yes
Recently 4 of 5 people (80%) answered Yes

Entry

How do you make the original text in a Label change randomly using a button?

Oct 1st, 2009 03:56
jsieoa gide, Scott Mandarich, Martin Franklin, chester willis,


from Tkinter import *
import random


def randomiseString(s):
    numlist=[]
    stringOut=[]
    while (len(numlist)<len(s)):
        ## give me a list of numbers between 0 and len(s)
        ## just don't repeat and stop when i've got enough
        num=random.randrange(0, len(labelText), 1)
        if num not in numlist:
            numlist.append(num)
    for num in numlist:
        stringOut.append(s[num])
    stringOut="".join(stringOut)
    
    return stringOut


-------------------------------------------------------------------------
http://regalosdenavidad1.blogspot.com/
http://vianocnedarceky.blogspot.com/
http://julklappar1.blogspot.com/
http://joululahjoista.blogspot.com/
http://christmasgifts213.blogspot.com/
http://vanocnidarky.blogspot.com/
http://festivalslavlja.blogspot.com/
http://festivalfestlighederne.blogspot.com/
http://festivaalienjuhlia.blogspot.com/
http://celebrationsdufestival.blogspot.com/
http://festivalfeiern.blogspot.com/
http://fesztivalunnepsegek.blogspot.com/
http://vraagantwoorden.blogspot.com/
http://repondalaquestion.blogspot.com/
http://otazkaodpovedi.blogspot.com/

-------------------------------------------------------------------------


root=Tk()

labelText="Random Label"


label=Label(root, text=labelText)
label.pack()


def setText():
    label["text"]=randomiseString(label["text"])
    
b=Button(root, text="Shuffle", command=setText)
b.pack()

root.mainloop()














http://www.golfgolfcourses.com/index.php?q=Delaware