Python Forum
[Tkinter] optimalization of code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] optimalization of code
#1
Hi guys can someone help me with optimalization of this code?
i got 5 chechk box (named Px) and 5 other (named Rx)
I wish: on begin all check box got status NORMAL, when we mark P1 we can't mark R1 (status DISABLED)- same thing relation between P2-R2, P3-R3 ... in two ways.
In def confirm i wrote algorythm but i think it's possible to make short way.
one think is wrong when we mark R1 at first then we mark P1, R1 got status DISABLED but mark will stay on it(dot). example : http://prntscr.com/op9ydv Confused

import numpy as np
s=np.zeros((10),dtype=object)
...
self.checkvars = [IntVar() for i in range(10)]

self.chk1 = Checkbutton(root, text='P1', var=self.checkvars[0], command=self.confirm)
self.chk2 = Checkbutton(root, text='P2', var=self.checkvars[1], command=self.confirm)...

self.chk11 = Checkbutton(root, text='R1', variable=self.checkvars[5], command=self.confirm)
self.chk12 = Checkbutton(root, text='R2', variable=self.checkvars[6], command=self.confirm)...

   def confirm(self):
        s[:] = [1 if v.get() else 0 for v in self.checkvars]

        if s[0] == 1:
            s[5]=0
            self.chk11.config(state=DISABLED)
        if s[0] == 0:
            self.chk11.config(state=NORMAL)
Reply


Messages In This Thread
optimalization of code - by storzo - Aug-06-2019, 10:07 PM
RE: optimalization of code - by Yoriz - Aug-07-2019, 05:18 AM
RE: optimalization of code - by storzo - Aug-07-2019, 05:35 AM
RE: optimalization of code - by Yoriz - Aug-07-2019, 05:42 AM
RE: optimalization of code - by storzo - Aug-07-2019, 05:50 AM
RE: optimalization of code - by storzo - Aug-07-2019, 07:15 PM

Forum Jump:

User Panel Messages

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