How to get a menu checkbutton to call a function in Python + Tkinter? -


so, i'm in personal project (just try myself) python + tkinter. encrypter, means gets piece of text , encrypts using famous cyphers (like numerical cypher, caesar's cypher, , others).
now, wanted give user option save text encrypted, , encrypted text generated program. that, created 2 checkbutton on program's menu: 1 "save text" , other "save encrypted text". question is, tried attach function it's command option, so, guess should run function when option clicked. isn't happening.
i'll explain funcitions shouls before passing code.
should prompt question, asking user if he/she wants create text file text , encrypted text (this isn't database, it's user able read later text's he/she encrypted , encrypted version, if he/she wants to). so, code:

encryptermenu = menu(menubar, tearoff=0) encryptermenu.add_checkbutton(label="save text", variable=v, command=savetext) encryptermenu.add_checkbutton(label="save encrypted text", variable=w, command=saveencryptedtext) menubar.add_cascade(label="encrypter", menu=encryptermenu) 

the checkbutton options, , functions:

def savetext():     sdtst = messagebox.askyesno(title="save text", message="a .txt file created @ same directory program save text decided encrypt. ok?")  def saveencryptedtext():     sdtset = messagebox.askyesno(title="save encrypted text", message="a .txt file created @ same directory program save encrypted text generated program. ok?") 

should checkbutton run function on-click or making confusion? anyway, hope me.

to answer specific question, yes, function called when click on checkbutton.

you should calling add_command rather add_checkbutton on menu. using checkbutton call function menu highly unusual , confuse users.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -