Python Forum
Creating a variables inside FOR loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a variables inside FOR loop
#4
Thanks everyone, I have managed to create variables using for loop with dictionaries as bowlofred mentioned:

def picking_gui():
    number=count_unique_devices(myConnection)
    print("number=",number)
    global devices
    devices = {}
    for x in range(1,number):
        devices["device{0}".format(x)] = canvas_tk.create_rectangle(20+(x*90),400,90+(x*90),470,fill='red')
        name_text = "device"+str(x)
        canvas_tk.create_text(55+(x*90),435,text=name_text)
        if(x>10):
            devices["device{10}".format(x)] = canvas_tk.create_rectangle(20+(x*90),500,90+(x*90),570,fill='red')
I now will have a look at how to create my GUI using OOP aproach as I have never used it before. It seems more complex than the usual program flow I am used to
Reply


Messages In This Thread
Creating a variables inside FOR loop - by zazas321 - Sep-11-2020, 06:21 AM
RE: Creating a variables inside FOR loop - by buran - Sep-11-2020, 06:48 AM
RE: Creating a variables inside FOR loop - by zazas321 - Sep-11-2020, 07:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable definitions inside loop / could be better? gugarciap 2 566 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 2,291 Nov-07-2023, 09:49 AM
Last Post: buran
  Help adding a loop inside a loop Extra 31 5,222 Oct-23-2022, 12:16 AM
Last Post: Extra
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,600 Jul-27-2022, 08:50 PM
Last Post: rob101
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,611 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  how to use 3 variables python loop evilcode1 2 1,761 Nov-12-2021, 11:43 AM
Last Post: jamesaarr
  creating a loop yk303 2 1,941 Feb-08-2021, 08:41 PM
Last Post: nilamo
  Adding to the dictionary inside the for-loop - weird behaviour InputOutput007 5 2,934 Jan-21-2021, 02:21 PM
Last Post: InputOutput007
  why print('\n') produced 2 new lines instead of 1 - Located inside a FOR loop JulyFire 2 2,668 Jan-10-2021, 01:50 AM
Last Post: JulyFire
  Two variables in loop Ferdis 1 1,614 Jul-24-2020, 10:18 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020