python - Connect a message box to a button -


i want able click button , have message box display code generated. here's part of code:

global s letters = [random.choice('bcdfghjkmpqrtvwxyyz')  x in range(19)] numbers = [random.choice('2346789') x in range(6)] s = letters + numbers random.shuffle(s) s = ''.join(s)  global code code = entry(state='readonly')  def callback():     code = entry(state='readonly', textvariable=s)  code.grid(row=0, pady=20) generate=photoimage(file='generate.gif') g = button(image=generate , command=callback, compound=center) g.grid(row=1, padx=206.5, pady=20)  

fixed few things comments:

from tkinter import * import random root = tk()  letters = [random.choice('bcdfghjkmpqrtvwxyyz')  x in range(19)] numbers = [random.choice('2346789') x in range(6)] s = letters + numbers random.shuffle(s) s = ''.join(s)  # rather use global variables, bad idea, can make callback creator function, takes formerly global variables arguments, , uses them create callback function. def makecallback(svariable):     def callback(): # set text of entry         svar.set(s)     return callback  # use stringvar alter text in entry svar = stringvar(root) # can use entry this, seems label more you're looking for. code = entry(root, state='readonly', textvariable=svar)  # create callback function callback = makecallback(svar)  code.grid(row=0, pady=20) generate=photoimage(file='generate.gif') g = button(root, image=none , command=callback, compound=center) g.grid(row=1, padx=206.5, pady=20)  

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -