Python Forum
Help with tkinter Button and Label interaction issues ...
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with tkinter Button and Label interaction issues ...
I'm new to tkinter (running on python 3.5) and I'm having some issues that I'm hoping I can get some help with.  Here's my code (really simple at this point):

from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter.filedialog import askdirectory
import winsound

def findsource():
   global filename,foldername
   filename = askopenfilename(parent=root,title="Choose Source CSV File & Folder to Convert")
   if ((filename != "") and (foldername != "")):
       CSVsource.set = filename

def findconvert():
   global foldername,filename
   foldername = askdirectory(parent=root,title="Choose Converted CSV Location",mustexist=True)
   if ((filename != "") and (foldername != "")):

def convertandsave():
   if (filename != ""):
           with open(filename,'r') as UseFile:
           print("No file exists")

root = Tk()
root.title("NSM CSV Converter - V.4.0")
root.resizable(0, 0)



CSVsource.set("C:\\Users\Chris Lyons\Documents\Snaps2")

errmsg = 'Error!'

l1 = Label(root, text='NSM CSV Converter', font=("Verdana",18))
l2 = Label(root, text='Source File Folder', font=("Times New Roman",9))
l3 = Label(root, text='Converted File Folder', font=("Times New Roman",9))
l4 = Label(root, textvariable=CSVsource, relief=SUNKEN, width=60, bg="white")
l5 = Label(root, textvariable=convertdest, relief=SUNKEN, width=60, bg="white")

b1 = Button(root, text='Convert and Save', font=("Verdana",12), command=convertandsave(), state=DISABLED)
b1.pack(), y=180)
b2 = Button(root, text='Browse', font=("Verdana", 12), command=findsource)
b2.pack(), y=75)
b3 = Button(root, text='Browse', font=("Verdana", 12), command=findconvert)
b3.pack(), y=125)

l1.pack(), y=10), y=60), y=110), y=80), y=130)

Here's the window this code is creating:

I have 2 labels (l4 & l5) that I need to update when the user choose buttons b2 & b3 and selects a file/folder and a folder.  I'm trying to use filedialog.askopenfilename and filedialog.askdirectory to get that information from the associated selection windows.  I've tested those and they seem to be working OK.  But I'm not sure if I'm dealing with executing them in their functions correctly and getting the data back to the main program properly.  Something isn't working.

The other 'Convert and Save' button (b1) is DISABLED until the user has selected a file/folder to process and a destination folder to place the processed file into.  Once those actions are done, b1 is set to NORMAL and is active.  This appears to be working correctly but the button doesn't appear to be running the convertandsave() function when pressed.  Can't figure out why.  Any ideas?

Again, new to tkinter and I'm sure I'm doing something stupid but I need to move on, so please guide me if you can.  Appreciate any help.

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter button image Nick_tkinter 4 307 Mar-04-2021, 11:33 PM
Last Post: deanhystad
  tkinter destroy label inside labelFrame Nick_tkinter 2 221 Feb-24-2021, 03:31 AM
Last Post: deanhystad
  tkinter python button position problem Nick_tkinter 3 522 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  TKinter restarting the mainloop when button pressed zazas321 7 686 Jan-26-2021, 06:38 AM
Last Post: zazas321
  tkinter touchscreen scrolling - button press makes unwanted scrolling nanok66 1 342 Dec-28-2020, 10:00 PM
Last Post: nanok66
  tkinter: Image to Label Maryan 10 791 Oct-29-2020, 01:48 PM
Last Post: joe_momma
  Tkinter - How can I remove the background borders from ttk.Button? TurboC 4 2,493 Oct-18-2020, 10:58 AM
Last Post: TurboC
  Tkinter - How can I extend a label widget? TurboC 2 449 Oct-13-2020, 12:15 PM
Last Post: zazas321
  tkinter | Button color text on Click Maryan 2 539 Oct-09-2020, 08:56 PM
Last Post: Maryan
  Tkinter: How to assign calculated value to a Label LoneStar 7 665 Sep-03-2020, 08:19 PM
Last Post: LoneStar

Forum Jump:

User Panel Messages

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