Okorosso

button hell for Serg

Apr 15th, 2021
467
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from tkinter import *
  2. from math import ceil
  3.  
  4. n, m = tuple(map(int, input().split()))
  5. button_array = [[None] * m]
  6.  
  7. tk = Tk(className="Button Hell")
  8. tk.geometry("450x300")
  9. gg = Grid()
  10.  
  11.  
  12. def get_button_number(bttn):
  13.     button_number = bttn._name.replace("!button", '')
  14.     if button_number == '':
  15.         button_number = 1
  16.     return int(button_number)
  17.  
  18.  
  19. def print_arr(arr):
  20.     with open("data.txt", "w") as file1:
  21.         for i in range(1, len(arr)):
  22.             file1.writelines(' '.join(arr[i][1::]) + '\n')
  23.  
  24.  
  25. def click(butn, columns_counter):
  26.     button_num = get_button_number(butn)
  27.     row = ceil(button_num / m)
  28.     col = button_num % m
  29.     if col == 0:
  30.         col = columns_counter
  31.     if butn['text'] == '1':
  32.         result = '0'
  33.     else:
  34.         result = '1'
  35.     button_array[row][col] = result
  36.     print_arr(button_array)
  37.     butn['text'] = result
  38.  
  39.  
  40. with open("data.txt", "r") as file:
  41.     for row_count in range(1, n + 1):
  42.         tmp = file.readline().split()
  43.         tmp = tmp[0:m]
  44.         button_array.append([None, *tmp])
  45.         columns_count = 1
  46.         for elem in tmp:
  47.             button = Button(tk, text=elem)
  48.             button["command"] = lambda btn=button: click(btn, m)
  49.             button.grid(row=row_count, column=columns_count)
  50.             columns_count += 1
  51.  
  52. tk.mainloop()
  53.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×