Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7761213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:04:46+00:00 2026-06-01T14:04:46+00:00

I have a problem with my python code. I am writing a GUI in

  • 0

I have a problem with my python code. I am writing a GUI in python using tkinter that displays several blocks with about 10 rows with 4 radiobuttons, an entry field and a scale in each row. Code below

    for r,v,mi,ma,i in zip(self.radiobuttonShapes, self.valueShapes, self.minShapes, self.maxShapes, range(1,10)):
        ttk.Label(self.Shape, text="Shape " + str(i)).grid(column=0, row=i)
        ttk.Radiobutton(self.Shape, text="Off", variable=r, value=1, command=self.resetAllRadiosShape).grid(column=1, row=i)
        ttk.Radiobutton(self.Shape, text="Max", variable=r, value=2, command=self.resetAllRadiosShape).grid(column=2, row=i)
        ttk.Radiobutton(self.Shape, text="Min", variable=r, value=3, command=self.resetAllRadiosShape).grid(column=3, row=i)
        ttk.Radiobutton(self.Shape, text="Approx", variable=r, value=4, command=self.resetAllRadiosShape).grid(column=4, row=i)
        ttk.Entry(self.Shape, textvariable=v).grid(column=5, row=i)
        ttk.Scale(self.Shape, from_=mi, to=ma, variable=v).grid(column=6, row=i)

This mostly works fine.
My problem arises when i want to add an label to put it all into and expand that label with another row including and entry field and a scale, to use with the approx option.

My problem consists of not being able to create the variables on the fly and be able to access them by their methods afterwards.

Might not be clear to understand, but i think the dummy code below makes it easier. I want to be able to make parts of it inactive (the approx field when approx is not chosen).

for i in 1 2 3 4 5 6 7 8 9
    self.outerLabel$(i) = ttk.Label(self.Shape).grid(row=i)
    self.upperLabel$(i) = ttk.Label(self.outerLabel$(i)).grid(row=0)
    ttk.Radiobutton(self.upperLabel$(i)).grid(column=0)
    ttk.Radiobutton(self.upperLabel$(i)).grid(column=1)
    ttk.Radiobutton(self.upperLabel$(i)).grid(column=2)
    ttk.Radiobutton(self.upperLabel$(i)).grid(column=3)
    ttk.Entry(self.upperLabel$(i)).grid(column=4)
    ttk.Scale(self.upperLabel$(i)).grid(column=5)
    self.lowerLabel$(i) = ttk.Label(self.outerLabel$(i)).grid(row=1)
    ttk.Entry(self.lowerLabel$(i)).grid(column=0)
    ttk.Scale(self.lowerLabel$(i)).grid(column=1)
    self.lowerLabel$(i).configure(state=DISABLED)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:04:47+00:00Added an answer on June 1, 2026 at 2:04 pm

    You should use a dictionary for this, instead of dynamic variable names, the setup code would look something like this:

    def __init__(self):
        self.outerLabels = {}
        self.upperLabels = {}
        # whatever else is currently in __init__()
    

    And wherever the code is from your question:

    for i in range(1, 10):
        self.outerLabels[i] = ttk.Label(self.Shape).grid(row=i)
        self.upperLabels[i] = ttk.Label(self.outerLabels[i]).grid(row=0)
        ttk.Radiobutton(self.upperLabels[i]).grid(column=0)
        ttk.Radiobutton(self.upperLabels[i]).grid(column=1)
        ttk.Radiobutton(self.upperLabels[i]).grid(column=2)
        ttk.Radiobutton(self.upperLabels[i]).grid(column=3)
        ttk.Entry(self.upperLabels[i]).grid(column=4)
        ttk.Scale(self.upperLabels[i]).grid(column=5)
        self.lowerLabels[i] = ttk.Label(self.outerLabels[i]).grid(row=1)
        ttk.Entry(self.lowerLabels[i]).grid(column=0)
        ttk.Scale(self.lowerLabels[i]).grid(column=1)
        self.lowerLabels[i].configure(state=DISABLED)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem concerning python packages and testing. I'm writing an application using wx
I have a problem with using Twisted for simple concurrency in python. The problem
Folks, I have a problem. I am a writing a script in python which
I'm writing some python code to interact with a C DLL that uses structures
I'm writing an application in Python that is going to have a lot of
I am writing some Python code to implement some of the concepts I have
I have a problem writing a file with Pickle in Python Here is my
I have the following python code that expects data coming from the serial port,
I am writing a script in Python using Selenium that auto fills out a
I have a problem in Python. How can I increment by one fully automatically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.