Here is an example of a random spin button using a button surrounded by labels to create the feeling of a spin animation. This example uses the Tkinter GUI and lets you select numbers 1 to 6. If your game requires more then this, just add additional labels. You are encouraged to experiment with this code and maybe locate the labels in a more circular fashion around the button.
# create a button surrounded by labels to mimic a random spin button # tested with Python24 vegaseat 23dec2006 import Tkinter as tk # use tk namespace for Tkinter items import random def make_labels(): """ create a list of labels and position them """ labels =  for k in range(1, 7): labels.append(tk.Label(root, text=' %d ' % k, bg='yellow')) # now assign a grid position to each label for ix, label in enumerate(labels): if ix < 3: label.grid(row=0, column=ix, pady=5) elif ix == 3: button1 = tk.Button(root, text='Press me', command=click) button1.grid(row=1, column=0, columnspan=3) label.grid(row=2, column=2, pady=5) else: label.grid(row=2, column=5-ix, pady=5) return labels def click(): """ loop/spin through the labels and pick one to stop at random """ # reset all labels to same color for label in labels: label.config(bg='yellow') # start with a time delay of 15 ms and increase it in the spins t = 15 stop = random.randint(19, 24) for x in range(0, stop): label = labels[x%6] root.after(t, label.config(bg='green')) root.update() root.title(str(x%6 + 1)) # test if x == stop-1: # final result available via var1.get() var1.set(str(x%6 + 1)) break root.after(t, label.config(bg='yellow')) t += 15 # create the window form root = tk.Tk() # StringVar() updates result label automatically var1 = tk.StringVar() # set initial value var1.set("") # create the result label result = tk.Label(root, textvariable=var1, fg='red') result.grid(row=3, column=0, columnspan=3) # create the list of labels labels = make_labels() # start of program event loop root.mainloop()
Are you able to help answer this sponsored question?
Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.
How to connect device scanner with visual basic, its analogy I made button scan in vb and typing button scan in press scanner live and walk .. how? Help ...
I want to write out a DXF file with line arc and maybe spline.
My issue is documentation; While I have looked at AutoCAD's site I feel that there isnt ...
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then For Each subCtrl As Control In ctrl.Controls If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then MsgBox(subCtrl.Text) End If If subCtrl.GetType Is ...