How to let the frame go top in tkinter? I tried to use both grid and place, both useless. Also, I want to display a small float window while I click any button to let me select confirm or cancel. Could you let me know hwo to create the float windows in tkinter
class MYGUI():
def __init__(self, root) -> None:
self.root = root
self.btn_list_names = list(range(9,-1,-1)) ['.','←']
self.btn_list_btns = []
self.btn_list_cmd={
9:self.btn_9,
8:self.btn_8,
7:self.btn_7,
6:self.btn_6,
5:self.btn_5,
4:self.btn_4,
3:self.btn_3,
2:self.btn_2,
1:self.btn_1,
0:self.btn_0,
'.':self.btn_dot,
'←':self.btn_delete,
}
self.numpad_frame = Frame(self.root,width=200,height=250,bg='blue')
self.numpad_create()
def btn_9(self):
self.test_entry.focus_get().insert(END,'9')
def btn_8(self):
self.test_entry.focus_get().insert(END,'8')
def btn_7(self):
self.test_entry.focus_get().insert(END,'7')
def btn_6(self):
self.test_entry.focus_get().insert(END,'6')
def btn_5(self):
self.test_entry.focus_get().insert(END,'5')
def btn_4(self):
self.test_entry.focus_get().insert(END,'4')
def btn_3(self):
self.test_entry.focus_get().insert(END,'3')
def btn_2(self):
self.test_entry.focus_get().insert(END,'2')
def btn_1(self):
self.test_entry.focus_get().insert(END,'1')
def btn_0(self):
self.test_entry.focus_get().insert(END,'0')
def btn_dot(self):
self.test_entry.focus_get().insert(END,'.')
def btn_delete(self):
value = self.test_entry.focus_get().get()
self.test_entry.focus_get().delete(0,END)
self.test_entry.focus_get().insert(END,value[:-1])
def setup(self):
self.root.geometry('1068x681 10 10')
self.test_entry = Entry(self.root)
self.test_entry.place(x=0,y=0,width=100,height=20)
self.test_entry.bind("<FocusIn>", lambda event:self.numpad_frame.place(x=105,y=25))
self.test_entry1 = Entry(self.root)
self.test_entry1.place(x=0,y=25,width=100,height=20)
self.test_entry1.bind("<FocusIn>",lambda event:self.numpad_frame.place(x=105,y=45))
self.test_entry2 = Entry(self.root)
self.test_entry2.place(x=105,y=0,width=100,height=20)
self.test_entry2.bind("<FocusIn>", lambda event:self.numpad_frame.place(x=205,y=25))
self.test_entry3 = Entry(self.root)
self.test_entry3.place(x=105,y=25,width=100,height=20)
self.test_entry3.bind("<FocusIn>",lambda event:self.numpad_frame.place(x=205,y=45))
def numpad_create(self):
sr,sc=0,0
init_sc = sc
for b in self.btn_list_names:
cmd = self.btn_list_cmd[b]
Button(self.numpad_frame, text=b, width=5,command=cmd).grid(row=sr,column=sc)
sc = 1
if sc>=init_sc 3:
sr =1
sc= init_sc
please have a look the codes, thank you so much if could give me some suggestions
CodePudding user response:
Call tkraise()
for the frame everywhere (Every Entry widget in your case) you are willing the frame to be rise above:
self.test_entry.bind("<FocusIn>", lambda event:self.numpad_frame.place(x=105,y=25), self.numpad_frame.tkraise())
Could you let me know how to create the float windows in tkinter?
You can use tkinter.messagebox for such purpose. Use messagebox.askokcancel to ask the user to select between confirm or cancel.
PS: Try to place the frame at coordinates such that it does not overlap with the Entry widgets, as is happening in your case, because it builds a pretty poor UI. And please provide a minimal reproducible example when you ask a question.