There is code using the tkinter library:

 from tkinter import * import pickle import time import random class MainWindow: def __init__(self): Label(root, text="Set our sets by our own:", font="Arial 14", width=20, height=2, justify=LEFT).grid(column=0, row=2, columnspan=3) Label(root, text='A:').grid(column=0, row=3, sticky=E) Label(root, text='B:').grid(column=0, row=4, sticky=E) Label(root, text='C:').grid(column=0, row=5, sticky=E) Label(root, text='Set our sets by random:', font="Arial 14", width=30, height=2, justify=LEFT)\ .grid(column=0, row=6, columnspan=3) Label(root, text='Amount of A\'s items:').grid(column=0, row=7, sticky=E) Label(root, text='Amount of B\'s items:').grid(column=0, row=8, sticky=E) Label(root, text='Amount of C\'s items:').grid(column=0, row=9, sticky=E) entA = Entry(root, width=30, bd=3, state=DISABLED) entA.grid(column=1, row=3) entB = Entry(root, width=30, bd=3, state=DISABLED) entB.grid(column=1, row=4) entC = Entry(root, width=30, bd=3, state=DISABLED) entC.grid(column=1, row=5) lenA = Entry(root, width=10, bd=3, state=DISABLED) lenA.grid(column=1, row=7, sticky=W) lenB = Entry(root, width=10, bd=3, state=DISABLED) lenB.grid(column=1, row=8, sticky=W) lenC = Entry(root, width=10, bd=3, state=DISABLED) lenC.grid(column=1, row=9, sticky=W) self.create_RadioButtons() def create_RadioButtons(self): var = IntVar() var.set(0) rad0 = Radiobutton(root, text="Вy our own:", variable=var, value=0, command=self.vruchnu) rad1 = Radiobutton(root, text="By random:", variable=var, value=1, command=) rad0.grid(column=0, row=0, columnspan=2, sticky=W) rad1.grid(column=0, row=1, columnspan=2, sticky=W) def vruchnu(self): global A, B, C self.entA['state']=NORMAL entB['state']=NORMAL entC['state']=NORMAL lenA['state']=DISABLED lenB['state']=DISABLED lenC['state']=DISABLED root = Tk() root.title("Laboratory work 1") root.geometry("680x400") obj = MainWindow() root.mainloop() 

Why in the vruchnu(self) method I do not have access to the variables entA , entB , lenA ?

  • because they are not distributed to global variables in the class. make self.entA , etc - Twiss
  • the same is true ... - Artem Aleksandrovich
  • self.entA['state']=NORMAL - Artem Aleksandrovich
  • one
    in __init__ also do the same instead of entA change to self.entA - Twiss
  • exactly thank you - Artem Aleksandrovich

1 answer 1

In order for you to display Entry you need to bind this widget to the class ie there will be self.entA as a result of which you can use not only in one function, but in the whole class .

Corrected program code:

 from tkinter import * import pickle import time import random class MainWindow: def __init__(self): Label(root, text="Set our sets by our own:", font="Arial 14", width=20, height=2, justify=LEFT)\ .grid(column=0, row=2, columnspan=3) Label(root, text='A:').grid(column=0, row=3, sticky=E) Label(root, text='B:').grid(column=0, row=4, sticky=E) Label(root, text='C:').grid(column=0, row=5, sticky=E) Label(root, text='Set our sets by random:', font="Arial 14", width=30, height=2, justify=LEFT)\ .grid(column=0, row=6, columnspan=3) Label(root, text='Amount of A\'s items:').grid(column=0, row=7, sticky=E) Label(root, text='Amount of B\'s items:').grid(column=0, row=8, sticky=E) Label(root, text='Amount of C\'s items:').grid(column=0, row=9, sticky=E) self.entA = Entry(root, width=30, bd=3, state=DISABLED) self.entA.grid(column=1, row=3) self.entB = Entry(root, width=30, bd=3, state=DISABLED) self.entB.grid(column=1, row=4) self.entC = Entry(root, width=30, bd=3, state=DISABLED) self.entC.grid(column=1, row=5) self.lenA = Entry(root, width=10, bd=3, state=DISABLED) self.lenA.grid(column=1, row=7, sticky=W) self.lenB = Entry(root, width=10, bd=3, state=DISABLED) self.lenB.grid(column=1, row=8, sticky=W) self.lenC = Entry(root, width=10, bd=3, state=DISABLED) self.lenC.grid(column=1, row=9, sticky=W) var = IntVar() var.set(0) rad0 = Radiobutton(root, text="Вy our own:", variable=var, value=0, command=self.vruchnu) # rad1 = Radiobutton(root, text="By random:", variable=var, value=1, command=self.vruchnu) rad0.grid(column=0, row=0, columnspan=2, sticky=W) # rad1.grid(column=0, row=1, columnspan=2, sticky=W) def vruchnu(self): self.entA['state'] = NORMAL self.entB['state'] = NORMAL self.entC['state'] = NORMAL self.lenA['state'] = DISABLED self.lenB['state'] = DISABLED self.lenC['state'] = DISABLED root = Tk() root.title("Laboratory work 1") root.geometry("680x400") obj = MainWindow() root.mainloop()