Python Forum
Please help to make the code smaller
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help to make the code smaller
#2
One way to go about it would be to put all of those labels into a list like so:

from tkinter import *
 
window = Tk()
 
data = [['100%', '80%', '60%', '40%', '20%', '10%'],
		['100%', '90%', '55%', '30%', '10%', '0%']]
 
labels = []

for x in range (6) :
	labels.append (Label(window, text="..."))
	labels [x].grid ()
 
def recall1():
	for x in range (6) :
		labels [x].configure(text=data[0][x])
 
 
def recall2():
	for x in range (6) :
		if x == 0 : y = 0
		else : y = 1
		labels [x].configure(text=data[y][x])

recallButton1 = Button(window, text="Recall Scene 1", padx=50, command=recall1)
recallButton2 = Button(window, text="Recall Scene 2", padx=50, command=recall2)
recallButton1.grid()
recallButton2.grid()
 
window.mainloop()
dexomol likes this post
Reply


Messages In This Thread
Please help to make the code smaller - by dexomol - Feb-22-2021, 08:08 PM
RE: Please help to make the code smaller - by BashBedlam - Feb-22-2021, 10:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  help me make this code better please (basic) bntayfur 4 2,669 Jun-16-2020, 04:20 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

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