Advertisement
tarrac

Untitled

Mar 21st, 2023
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. from tkinter import Entry, Tk, Frame, Label
  2.  
  3. class IpEntry(Frame):
  4.  
  5.     def __init__(self, font_size=12):
  6.         super().__init__()
  7.         self.font_size = font_size
  8.         print(type(font_size))
  9.         self.configure(
  10.             # background='red',
  11.             width=158,
  12.             # height=self.font_size*4+6,
  13.             # font=font
  14.         )
  15.         # print(font_size)
  16.         font = f'Courier {font_size}'
  17.         self.pic1 = Label(self, width=1, text='.')
  18.         self.pic2 = Label(self, width=1, text='.')
  19.         self.pic3 = Label(self, width=1, text='.')
  20.  
  21.         self.octet1 = Entry(self, width=3)
  22.         self.octet2 = Entry(self, width=3)
  23.         self.octet3 = Entry(self, width=3)
  24.         self.octet4 = Entry(self, width=3)
  25.  
  26.         # self.lbl_ip = Label(self, text='0.0.0.0')
  27.  
  28.         # Выравниквание контроллов
  29.         start_x = 2
  30.         start_y = 2
  31.         step=42
  32.  
  33.         self.pic1.place(x=start_x+step-13, y=start_y)
  34.         self.pic2.place(x=start_x+step*2-13, y=start_y)
  35.         self.pic3.place(x=start_x+step*3-13, y=start_y)
  36.  
  37.         self.octet1.place(x=start_x, y=start_y)
  38.         self.octet2.place(x=start_x+step, y=start_y)
  39.         self.octet3.place(x=start_x+step*2, y=start_y)
  40.         self.octet4.place(x=start_x+step*3, y=start_y)
  41.  
  42.         self.octet1.bind('<KeyRelease>', self.text_verification)
  43.         self.octet2.bind('<KeyRelease>', self.text_verification)
  44.         self.octet3.bind('<KeyRelease>', self.text_verification)
  45.         self.octet4.bind('<KeyRelease>', self.text_verification)
  46.  
  47.  
  48.     def text_verification(self, a):
  49.         octet = []
  50.         octet.append(self.octet1.get())
  51.         octet.append(self.octet2.get())
  52.         octet.append(self.octet3.get())
  53.         octet.append(self.octet4.get())
  54.         self.ip = '.'.join(octet)
  55.  
  56.  
  57.     def get_ip(self):
  58.         return self.ip
  59.  
  60. class TopFrame(Frame):
  61.     def __init__(self):
  62.         super().__init__()
  63.         self.configure(
  64.             # background='blue',
  65.             width=265,
  66.             height=26,
  67.         )
  68.         self.lbl_ip_address = Label(self, text = 'Введите ip адрес')
  69.         self.ip = IpEntry()
  70.  
  71.         self.lbl_ip_address.place(x=5, y=2, height=25)
  72.         self.ip.place(x=110, y=5, height=25)
  73.  
  74.         # return self
  75.  
  76. if __name__ == '__main__':
  77.  
  78.     root = Tk()
  79.     root.geometry('300x200')
  80.     root.configure(background='blue' )
  81.     root.top_frame = TopFrame()
  82.     root.top_frame.place(x=5, y=5)
  83.     root.mainloop()
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement