473,889 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding an option on the fly (Tkinter)

I am making use of a Checkbutton widget. However, I would like to add
an option or method "on the fly." For example I would like to bind a
filename ("filename.txt" ) to a particular Checkbutton widget so that I
call it later as:

widget["filename"]

Is this possible to do?

Thanks,

Harlin

Jul 18 '05 #1
3 1431
Harlin Seritt wrote:
I am making use of a Checkbutton widget. However, I would like to add
an option or method "on the fly." For example I would like to bind a
filename ("filename.txt" ) to a particular Checkbutton widget so that I
call it later as:

widget["filename"]

Is this possible to do?


Yes. Use dicts to store these buttons so that you can later refer to them.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Would I do this like:

buttondict = {button1, "name.txt"}

??

Thanks,

Harlin

Jul 18 '05 #3
Harlin Seritt wrote:
Would I do this like:

buttondict = {button1, "name.txt"}


If you want to.... but I guess the other way round makes more sense. And the
syntax is wrong, its supposed to be

{key : value, ...}

The point is that you can create buttons as much as you want - in a for loop
for example - but usually its important to keep _some_ reference to it so
you can alter it later - e.g. disable it. But you don't _have_ to, if you
don't want to touch it after creation. Something like this might give you
the idea:
cbs = {}
for name in filenames:
# I don't know the real expression for creating a button - but you
should, and this illustrates the idea
cb = check_button(pa rent, command=lambda name=name: do_something(na me))
cbs[name] = cb

Later, in do_something(na me), you could e.g. say:

def do_something(na me):
cbs[name].config(enabled =False)

Of course this means that cbs has to be a global var. But there exist other
options of course - as part of a object or whatever. that depends on your
code.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #4

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

Similar topics

11
2100
by: Harlin Seritt | last post by:
There are certain options for Tkinter widgets that have default values that I don't much care for (borderwidth, font come to mind) and continuously change when I'm building interfaces. With a bit of tweaking I have been able to give the widgets a look that rivals the best of them. However, I get tired of doing this when I'm writing code and would like a way that I could universally change them on my system. I have tried to find where in...
1
2503
by: Harlin Seritt | last post by:
I am working on making something called a PopMsg widget which is actually identical to a Balloon widget from Pmw. Here is the code: ---code--- from Tkinter import * import time class PopMsg: def showmsg(self, event):
0
1367
by: max(01)* | last post by:
hello everybody. i am a a bit of a newbie in python/tkinter,and i am experimenting a bit with widgets like checkbuttons. in python, you can create a checkbutton instance like this: ..... self.tergicristalli = IntVar() self.b1 = Checkbutton(self.pulsanti_spunta)
0
3595
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust accordingly. However, what I really want to happen is that the area of the canvas that the scrollbars show (the Scrollregion) should expand as the window grows. It doesn't currently do this. although, if the window shrinks smaller than the...
1
3611
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings Panel. I just want it to bring up one. Is there an easy way to do that?
2
2790
by: yorlina007 | last post by:
Hi I need to design a tkinter widget where i should have a browse option button as you see in all windows application to select a file from my machine. Also i need to select an integer from some dropdown box. How can i implement this... I m donewith the backend python coding.. but i need help for the front end.. I tried using the code which i got from google.. its like
0
810
by: oyster | last post by:
It is so funny that the official GUI lib for python is Tkinter, but I cannot find an articles which explains indetail how can we use thounsands of Tcl/Tk widget in Tkinter. For example, I have download the dll at http://www.hwaci.com/sw/tkhtml/index.html, renamed it to tkhtml12.dll and put it in H:\python25\bin\tcl\Tkhtml1.2\ then I edited a h:\python25\bin\tcl\Tkhtml1.2\pkgIndex.tcl file:
8
3295
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to my pc. But, it is not getting installed and is failing by throwing the below errors. Should i need to configure / install any specific files for resolving this issue ?
3
2992
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I guess my question is two-fold. 1) How do I get rid of that window? 2) Any comments in general? I am just learning python (and coding with classes), so I'm sure there are things I should pound into my head before I learn bad habits. Here's the...
0
9962
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9809
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11190
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10889
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10442
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9607
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7150
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3256
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.