473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Tkinter Menu Item Activation

Tkinter definitely deserves more respect! I'm making rapid progress
and it looks good.

But am stuck on this: I want the File/Save state to change from
disabled to enabled, depending on whether or not there is something to
save (Text modified). Google returns results in every language except
Python.

Sub problems: how to change state of menu item? how to detect changes
in Text widget?

Help appreciated.

Feb 22 '08 #1
3 3315
Ma************@gmail.com writes:
Tkinter definitely deserves more respect! I'm making rapid progress
and it looks good.

But am stuck on this: I want the File/Save state to change from
disabled to enabled, depending on whether or not there is something to
save (Text modified). Google returns results in every language except
Python.
Sub problems: how to change state of menu item? how to detect changes
in Text widget?

Help appreciated.
State of menu items can be changed like this:

<code>
import Tkinter as Tk

def hello():
if mfile.entrycget(2, 'state') == 'disabled':
state = 'normal'
else:
state = 'disabled'
mfile.entryconfigure(2, state=state)

root = Tk.Tk()
menubar = Tk.Menu(root)
mfile = Tk.Menu(menubar)
mfile.add_command(label="Open", command=hello)
mfile.add_command(label="Save", command=hello)
menubar.add_cascade(label='File', menu=mfile)
root.config(menu=menubar)
root.mainloop()
</code>

But I think that you should read this:
http://effbot.org/zone/vroom.htm

HTH,
Rob

Feb 22 '08 #2


Rob Wolfe wrote:
But I think that you should read this:
http://effbot.org/zone/vroom.htm
Rob, may the gods shower you with gold coins!
Feb 22 '08 #3
On Fri, 22 Feb 2008 13:30:06 +0100, <Ma************@gmail.comwrote:
[snip]
Sub problems: how to change state of menu item? how to detect changes
in Text widget?
If you have a reasonably recent tcl/tk version (>= 8.4), you should have a
edit_modified() method on your Text telling you if it has been modified
since you last called edit_modified(False).

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
Feb 26 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Humpty Dumpty | last post by:
Hi folks, here's a challenge: I have a dynamically created cascading menu in Tkinter that can be quite large because it is created from a file. I tried using lazy creation so only the menu item...
1
by: Eric Brunel | last post by:
Hi all, I'm in the process of localizing a Tkinter application and I'm struggling with a problem for which I can't figure out a solution. The following code: -------------------------------...
2
by: Stewart Midwinter | last post by:
I would like to link the contents of three OptionMenu lists. When I select an item from the first list (call it continents), the contents of the 2nd list (call it countries) would update. And in...
1
by: Philippe C. Martin | last post by:
Hi, I have he following need and do not find an easy way out: I have many menu items and would like them all to call the same method -However, I need the method called to react differently...
0
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
2
by: ishtar2020 | last post by:
Hi everybody I'd appreciate some help on creating a tear off menu with TkInter. I've been reading some documentation but still no luck. Please don't get confused: when I mean "tear off" menu I...
2
by: Andrew Trevorrow | last post by:
Our app uses embedded Python to allow users to run arbitrary scripts. Scripts that import Tkinter run fine on Windows, but on Mac OS X there is a serious problem. After a script does "root = Tk()"...
6
by: Gigs_ | last post by:
I'm writing text editor. How to enable/disable (cut, copy etc.) when text is selected/not selected
3
by: Eric Brunel | last post by:
Hello all, I'm trying out Python 2.6 and I found what might be a bug in the Tkinter module. How can I report it? The possible bug is a traceback when trying to delete a menu item in a menu...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.