I have a form which is having multiple rows. By pressing enter it opens up a option window. But every time i hit enter it opens a new option window. How can i control and check if an option window is open then don't open an option window.
import tkinter as tk
from tkinter import ttk
from tkinter import *
from tkinter import messagebox
# Directory/File processing libraries
import os
import configparser
import csv
def callback():
#messagebox.showinfo("Netezza", Folder_Name_var.get())
#messagebox.showinfo("Netezza", Table_Name_var.get() )
config = configparser.ConfigParser()
config.read('C:\\aa\\config.ini')
#for value in config['Folder']: print(value)
for key in config.items('Folder'):
print (key[1].replace('{Folder_Name}',Folder_Name_var.get()))
os.makedirs(key[1].replace('{Folder_Name}',Folder_Name_var.get()),exist_ok=True)
def click_tv(event):
#messagebox.showinfo("Inside")
selected=trv.focus()
print(trv.item(selected))
def press_enter(event):
#messagebox.showinfo("Inside")
selected=trv.focus()
print(trv.item(selected))
print(str((event.keysym)))
if str((event.keysym))=='Return':
option_wnd=Toplevel(root)
option_wnd.geometry('200x200')
option_wnd.title('Option Window')
option_wnd.grab_set()
#option_wnd.pack()
def selection_change(event):
selected = trv.selection()[0]
print('You clicked on', trv.item(selected))
#option_wnd.mainloop()
root = Tk()
Folder_Name_var = tk.StringVar()
Table_Name_var = tk.StringVar()
# This is the section of code which creates the main window
root.geometry('873x498')
root.configure(background='#63B8FF')
root.title('Automation Software - Blue Shield of California')
pic= Canvas(root, height=100, width=100)
#pic= Canvas(root, height=225, width=580)
#picture_file = PhotoImage(file = 'c:\\aa\\bsc.png')
#pic.create_image(0, 0, anchor=NW, image=picture_file)
#pic.place(x=5, y=5)
lbl_Folder_Name = Label(root, text="Folder Name",background='#63B8FF').place(x=600, y=50)
lbl_Table_Name = Label(root, text="Table Name",background='#63B8FF').place(x=600, y=90)
txt_Folder_Name = Entry(root,textvariable = Folder_Name_var).place(x=700, y=50)
txt_Table_Name = Entry(root,textvariable = Table_Name_var).place(x=700, y=90)
Button(root, text="Show", width=10, command=callback).place(x=700,y=120)
tree_frame=Frame(root)
tree_frame.place(x=10,y=260)
tree_scroll=Scrollbar(tree_frame)
tree_scroll.pack(side=RIGHT,fill=Y)
style=ttk.Style()
style.theme_use("default")
style.map("Treeview",background=[('selected','bisque2')],foreground=[('selected','black')])
trv= ttk.Treeview(tree_frame,yscrollcommand=tree_scroll.set, columns=(1,2,3), show="headings", height="10")
trv.heading(1,text="Parameter", anchor=W)
trv.heading(2,text=" Parameter Description", anchor=W)
trv.heading(3,text=" Specify your value", anchor=W)
trv.tag_configure('even',background="white")
trv.tag_configure('odd',background="steelblue")
trv.bind("<Double-1>",click_tv)
trv.bind("<Return>",press_enter)
trv.bind("<<TreeviewSelect>>",selection_change)
trv.pack()
tree_scroll.config(command=trv.yview)
i=1
with open("c:\\aa\control.txt") as options:
options_line = csv.reader(options, delimiter='\t')
for option in options_line:
#a=1
if i%2==0:
trv.insert(parent='', index='end', values=(option), tags=('even',))
#print("even")
else:
trv.insert(parent='', index='end', values=(option), tags=('odd',))
#print("odd")
i=i+1
#trv.place(x=100,y=260)
root.mainloop()
Everytime I hit enter on the root window it opens a pop up window. I need to control the it. if the pop up window is open then we should not allow another pop up to open.

option_wnd.grab_set()insidepress_enter(), so you cannot trigger anotherEnterkey press event on the treeview. So I wonder how can you open anotheroption_wndwithout closing the existing one?