From Vasilis.Vlachoudis at cern.ch Wed Mar 4 10:33:07 2020 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Wed, 4 Mar 2020 15:33:07 +0000 Subject: [Tkinter-discuss] (no subject) Message-ID: <0BC70B5D93E054469872FFD0FE07220E02E64F72B8@CERNXCHG51.cern.ch> I had the impression that tkinter is single threaded, but it seems that the breakpoint() or input() does not block the mainloop to continue If one clicks the second button that waits for an input or enter in the breakpoint() the mainloop is still responsive while it waits for an input. So one can click any button the first to display the message or the second that will abort with a message that readline cannot be re-entered? Why is that? What other commands can trigger such a behavior? import tkinter as tk def boinc(): for i in range(10): print("boinc...") def debug(): #breakpoint() print("Breakpoint") print("Input: ",end="") s = input() print("Entered:", s) #------------------------------------------------------------------------------- if __name__ == "__main__": root = tk.Tk() b = tk.Button(root, text="Boinc", command=boinc) b.pack() b = tk.Button(root, text="Debug", command=debug) b.pack() root.mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From aivar.annamaa at gmail.com Wed Mar 4 15:47:26 2020 From: aivar.annamaa at gmail.com (Aivar Annamaa) Date: Wed, 4 Mar 2020 22:47:26 +0200 Subject: [Tkinter-discuss] (no subject) In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E02E64F72B8@CERNXCHG51.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E02E64F72B8@CERNXCHG51.cern.ch> Message-ID: This question is discussed here: https://stackoverflow.com/questions/20891710/what-magic-prevents-tkinter-programs-from-blocking-in-interactive-shell Best regards, Aivar On 04.03.2020 17:33, Vasilis Vlachoudis wrote: > I had the impression that tkinter is single threaded, but it seems > that the breakpoint() or input() > does not block the mainloop to continue > If one clicks the second button that waits for an input or enter in > the breakpoint() > the mainloop is still responsive while it waits for an input. So one > can click any button > the first to display the message or the second that will abort with a > message that readline cannot > be re-entered? > > Why is that? What other commands can trigger such a behavior? > > import tkinter as tk > > def boinc(): > for i in range(10): > print("boinc...") > > def debug(): > #breakpoint() > print("Breakpoint") > print("Input: ",end="") > s = input() > print("Entered:", s) > > #------------------------------------------------------------------------------- > if __name__ == "__main__": > root = tk.Tk() > b = tk.Button(root, text="Boinc", command=boinc) > b.pack() > b = tk.Button(root, text="Debug", command=debug) > b.pack() > root.mainloop() > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: From slystoner at gmail.com Fri Mar 6 17:38:34 2020 From: slystoner at gmail.com (slY) Date: Fri, 6 Mar 2020 23:38:34 +0100 Subject: [Tkinter-discuss] StringVar update using gettext Message-ID: Hi all, I'm using Tkinter for the first time in a small project where multi-language functionality is necessary. I'm using gettext for handling it together with StringVar. Is there a mechanism that saves me from having to make a call to the set() function for each StringVart involved? Here below some code to better explain me. Thank you very much. slY def set_language(lang): current_lang = gettext.translation("translation", localedir="locale", languages=[lang]) current_lang.install() my_string_var1.set(msg1) my_string_var2.set(msg2) my_string_var3.set(msg3) ... msg1 = _("lorem") msg2 = _(".ipsum") msg3 = _("dolor") ... my_string_var1 = tk.StringVar() my_string_var2 = tk.StringVar() my_string_var3 = tk.StringVar() my_string_var1.set(msg1) my_string_var2.set(msg2) my_string_var3.set(msg3) ... Button(left, image=eng_img, borderwidth=0, command=lambda : set_language("en")).grid(row=0, column=1) Button(left, image=fra_img, borderwidth=0, command=lambda : set_language("es")).grid(row=1, column=1) Button(left, image=ita_img, borderwidth=0, command=lambda : set_language("de")).grid(row=2, column=1) msg1_label = Label(right, textvariable=my_string_var1).grid(row=0, column=1) msg2_label = Label(right, textvariable=my_string_var2).grid(row=1, column=1) msg3_label = Label(right, textvariable=my_string_var3).grid(row=2, column=1) ... From nov49939 at gmail.com Tue Mar 31 02:37:53 2020 From: nov49939 at gmail.com (Pakistan Beauty) Date: Tue, 31 Mar 2020 11:37:53 +0500 Subject: [Tkinter-discuss] How to filter data using listbox in python from using csv file using TkTreectrl library Message-ID: I have this list box ####################################################################### import tkinter from TkTreectrl import * # define some data to insert into the list: data = { 'Joe': 1000.00, 'Jill': 738.39, 'Jack': 625.11, 'Jane': 99.99 } root = tkinter.Tk() # create list with scrollbars slistbox = ScrolledMultiListbox(root) slistbox.pack(fill='both', expand=1) listbox = slistbox.listbox # create columns listbox.configure(columns=('Paid', 'Customer', 'Debt')) #### add checkbox support to the listbox #### # checkbox icons: checked = tkinter.PhotoImage(data=(r'R0lGODlhDQANABEAACwAAAAADQANAIEAAAB/f3/f3' '9////8CJ4yPNgHtLxYYtNbIbJ146jZ0gzeCIuhQ53NJVNpmryZqsYDnemT3BQA7')) unchecked = tkinter.PhotoImage(data='R0lGODlhDQANABEAACwAAAAADQANAIEAAAB/f3' '/f39////8CIYyPNgHtLxYYtNbIrMZTX+l9WThwZAmSppqGmADHcnRaBQA7') # create treectrl state, element and style for the checkboxes: listbox.state_define('Checked') imgCheck = listbox.element_create( type='image', image=(checked, 'Checked', unchecked, ())) icon_style = listbox.style_create() listbox.style_elements(icon_style, listbox.element('select'), listbox.element('text'),imgCheck) listbox.style_layout(icon_style, imgCheck, padx=3, pady=2) listbox.style(0, icon_style) # define checkbox callback that will be bound to mouse-button-1 events: def cmd(event): # check which element was clicked identify = listbox.identify(event.x, event.y) # identify might be None or look like: # ('item', '2', 'column', '0') or # ('item', '3', 'column', '0', 'elem', 'pyelement3') if identify: try: item, column, element = identify[1], identify[3], identify[5] if element == imgCheck: # toggle the "checked" state listbox.itemstate_forcolumn(item, column, '~Checked') # do something, dependent on the current state of the checkbox new = listbox.itemstate_forcolumn(item, column) if new and 'Checked' in new: # the checkbox was newly checked print('Checked item', item, 'in column', column) # example: debts are paid, set "Debt" to 0.00 listbox.itemelement_configure(item, listbox.column(2), listbox.element('text'), text='0.00') else: # example: no payment received, set debt to stored value print('Unchecked item', item, 'in column', column) customer = listbox.itemelement_cget( item, listbox.column(1), listbox.element('text'), 'text') debt = data[customer] listbox.itemelement_configure(item, listbox.column(2), listbox.element('text'), text=debt) except IndexError: # we did not hit the checkbox, never mind pass # bind the callback to button 1 events listbox.bind('<1>', cmd) # insert data into the list to see if this works: for customer in data: listbox.insert('end', '', customer, data[customer]) root.mainloop() ############################################################################### And I want to use this search box function in this list box ###########################################################################333 from tkinter import * # First create application class class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.pack() self.create_widgets() # Create main GUI window def create_widgets(self): self.search_var = StringVar() self.search_var.trace("w", lambda name, index, mode: self.update_list()) self.entry = Entry(self, textvariable=self.search_var, width=13) self.lbox = Listbox(self, width=45, height=15) self.entry.grid(row=0, column=0, padx=10, pady=3) self.lbox.grid(row=1, column=0, padx=10, pady=3) # Function for updating the list/doing the search. # It needs to be called here to populate the listbox. self.update_list() def update_list(self): search_term = self.search_var.get() # Just a generic list to populate the listbox lbox_list = ['Adam', 'Lucy', 'Barry', 'Bob', 'James', 'Frank', 'Susan', 'Amanda', 'Christie'] self.lbox.delete(0, END) for item in lbox_list: if search_term.lower() in item.lower(): self.lbox.insert(END, item) root = Tk() root.title('Filter Listbox Test') app = Application(master=root) print('Starting mainloop()') app.mainloop() ##################################################################### -------------- next part -------------- An HTML attachment was scrubbed... URL: