Python Forum
[Tkinter] tkinter - unexpected output - don't know how func is triggered before calling
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] tkinter - unexpected output - don't know how func is triggered before calling
#1
This is how my app looks like in the image below
[Image: 4jBdPFH]

WHAT I AM TRYING TO DO:
I am trying to create a desktop app using tkinter where I have a Entry (Textbox) to enter a module name and press on a button which calls a function that does dir(given_module_name) and displays the list in a Listbox.
Questions:
1) Somehow, when I first run my program, the Listbox is automatically being populated before pressing the button. I am not sure why this is happening.
2) When I click on the button, nothing is happening. Why

I am noob in python and I am sure I am doing something wrong somewhere but not able to figure out where.

Thanks,
Om

Here is my code:
from tkinter import *

window = Tk()
window.title("Python Help")


def lib_func(lib):
    print("Entered lib_func()----->")
    func_list = dir(lib)
    for item in func_list:
        list1.insert(END, item)
 

#lib_name="os"
#lib_funcs(lib_name)

text_label = Label(window,text="Enter lib")
text_label.grid(row=0,column=0)

str_var=StringVar()
#print("str_val type is: ",type(str_var)) #str_val type is:  <class 'tkinter.StringVar'>

# This part is confusing where the text typed in text_entry is fetched from str_val
text_entry = Entry(window,textvariable=str_var)
text_entry.grid(row=0, column=1)

list1=Listbox(window, height=30,width=35)
list1.grid(row=2,column=0,rowspan=6,columnspan=2)

enter_button = Button(window,text="Enter",command=lib_func(str_var.get()))
enter_button.grid(row=0,column=2)

window.mainloop()
Reply


Messages In This Thread
tkinter - unexpected output - don't know how func is triggered before calling - by omm - Dec-06-2018, 10:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter | entry output. Sap2ch 1 2,038 Sep-25-2021, 12:38 AM
Last Post: Yoriz
  [Tkinter] acceleration of data output in treeview tkinter Vladimir1984 4 4,259 Nov-21-2020, 03:43 PM
Last Post: Vladimir1984
  Displaying output in GUI ( Tkinter) Zouloutamtam 7 18,608 Sep-29-2020, 02:08 PM
Last Post: Zouloutamtam
  [Tkinter] calling a new window from a tkinter window neuroprogrammer 2 2,576 Jul-28-2020, 10:59 PM
Last Post: deanhystad
  [PyQt] Loop triggered by button help Purple0 1 2,356 May-17-2020, 02:57 AM
Last Post: deanhystad
  Active tkinter text output during loop dvanommen 2 10,845 Oct-18-2019, 02:23 PM
Last Post: dvanommen
  sQlite3 output to tkinter treeview - how do I set / increase width of the output? dewijones67 5 6,727 Jan-23-2019, 08:45 AM
Last Post: Larz60+
  [Tkinter] Tkinter widgets driving Arduino uno output pins woodcncwnc 3 4,614 Jan-29-2018, 08:21 PM
Last Post: woodcncwnc

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020