I've just started using Tkinter myself, so maybe it's easy to do No matter where I looked, I couldn't find the ability to hold down the Button and lock it. If anyone knows how to do it, can you tell me?
I couldn't find a way to do it, so I tried to implement it forcibly. It's a pretty wicked way, so it may not be helpful, but I'll list it below.
I want to create a GUI that edits 8-bit binaries using buttons.
Can't I keep pushing with Tkinter Button? Button can be disabled. Button label (picture on the surface) can be changed But can't the relief of Button be changed?
I discarded the generated button and tried to recreate everything with relief as it was pushed again.
BinEditor.py
import sys
import tkinter as tk
class BinEditFrame(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.val = 0x00
self.bits = []
for i in range(8):
btn = tk.Button(self,text=str(i), relief='raised', command=self.callback(i))
btn.pack(sid='right')
self.bits.append(btn)
print("start")
def callback(self, i):
def push():
self.val ^= (1<<i)
print(self.val)
#All Button Delete
for bit in self.bits:
bit.destroy()
self.bits.clear()
#All Button ReCreate
for j in range(8):
if (self.val & (1<<j) > 0):
btn = tk.Button(self,text=str(j), relief='sunken',
command=self.callback(j) )
else:
btn = tk.Button(self,text=str(j), relief='raised',
command=self.callback(j) )
btn.pack(sid='right')
self.bits.append(btn)
return push
if __name__ == "__main__":
print("BinEditor")
win = tk.Tk()
be = BinEditFrame(win)
be.pack()
win.mainloop()
Recommended Posts