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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -