Python Forum
Tkinter Exit Code based on Entry Widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter Exit Code based on Entry Widget
#1
Hello All... I am new to this forum and quite new to Python, please forgive my ignorance. I am using this code for a basic Tkinter GUI and need to figure out how to properly exit the code if my entry widget is blank. I am using 2 GPIO inputs on a Raspberry Pi along with this GUI. In my "def update_clock" I am checking if the entry is there or not and simply changing the label based on that. What I want to do is, "IF" the entry widget is blank and GPIO.input (5) == 1, I want to override everything and still keep a message "TESTER NOT READY". Getting the status of the GPIO is a physical pushbutton. Not sure how to handle this. Please let me know if I am making no sense at all here.

#!/usr/bin/env python3

import tkinter as tk
import tkinter.ttk as ttk
import RPi.GPIO as GPIO
from tkinter import *
from tkinter import messagebox
import time
from datetime import datetime


GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.IN)
GPIO.setup(6, GPIO.IN)


class App(Frame):

    def __init__(self,master=None):
        Frame.__init__(self, master)
        root.attributes('-fullscreen', True)
        button = Button (master, text = "EXIT ESD", command = quit)
        button.place(x=375, y=280)

        tk.Label(master, text="Badge #",font=("Helvetica", 30)).grid(row=0)
        tk.Entry(root).place(x=170,y=10, width=200, height=40)
        self.master = master
        self.label = Label(text="", fg="blue", font=("Helvetica", 30))         
        self.label.place(x=40,y=150)
        self.entry_widget = tk.Entry(root, font=("Helvetica", 26))
        self.entry_widget.focus_set()
        self.entry_widget.place(x=170,y=10, width=200, height=40)                 	
        self.update_clock()
      

    def update_clock(self):
        d = datetime.now().strftime("%m-%d-%Y %H:%M:%S")
        newT = datetime.strptime(d, "%m-%d-%Y %H:%M:%S").strftime("%m-%d-%Y %I:%M:%S %p")
        now = time.strftime("%H:%M:%S")
        if not self.entry_widget.get():
            self.label.configure(text=newT + '\n' + '\n'"   NOT READY!  ", fg="red", font=("Helvetica", 24))
            self.label.place(x=60,y=100)
            self.after(1000, self.update_clock)
        else:
            self.label.configure(text=newT + '\n' + '\n'"    TESTER READY! ", fg="blue", font=("Helvetica", 24))
            self.label.place(x=60,y=100)
            self.after(1000, self.update_clock)
        

        if GPIO.input(5) == 1:
            text_entered = self.entry_widget.get()
            self.label.configure(text="PASS",fg="green", font=('Helvetica 110 bold'))
            self.label.place(x=48,y=100)
            self.after(40000, self.update_text)
            FileName = str("/home/pi/esd.txt")
            with open(FileName, "a") as f: # open file
                f.write("Badge# " + text_entered + ", Test PASSED ON: " + newT + '\n')
               
     
        elif GPIO.input(6) == 1:
            text_entered = self.entry_widget.get()
            self.label.configure(text="FAIL",fg="red", font=('Helvetica 110 bold'))
            self.label.place(x=80,y=100)
            self.after(50000, self.update_text)
            FileName = str("/home/pi/esd.txt")
            with open(FileName, "a") as f: # open file
                f.write("Badge# " + text_entered + ", Test FAILED ON: " + newT + '\n')

    def update_text(self):
        self.entry_widget.delete(0, 'end')

    def quit(self):
        root.destroy()


root = Tk()
app=App(root)
root.wm_title("ESD TESTER")
root.geometry("520x480")
root.after(1000, app.update_clock)
root.mainloop()
Reply


Messages In This Thread
Tkinter Exit Code based on Entry Widget - by Nu2Python - Oct-20-2021, 02:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: could not convert string to float: '' fron Entry Widget russellm44 5 983 Mar-06-2024, 08:42 PM
Last Post: russellm44
  TKinter Widget Attribute and Method Quick Reference zunebuggy 3 964 Oct-15-2023, 05:49 PM
Last Post: zunebuggy
  [Tkinter] entry widget DPaul 5 1,662 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 5,256 Jun-26-2022, 06:26 PM
Last Post: menator01
  Can't get tkinter button to change color based on changes in data dford 4 3,516 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] Making entry global in tkinter with multiprocessing luckyingermany 2 2,386 Jan-21-2022, 03:46 PM
Last Post: deanhystad
  [Tkinter] Update variable using tkinter entry methon drSlump 6 5,370 Oct-15-2021, 08:01 AM
Last Post: drSlump
  Tkinter | entry output. Sap2ch 1 2,054 Sep-25-2021, 12:38 AM
Last Post: Yoriz
  auto-generate code for Entry box location snakes 1 1,961 May-07-2021, 08:30 PM
Last Post: Yoriz
  .get() from generated Entry widgets in tkinter snakes 4 4,363 May-03-2021, 11:26 PM
Last Post: snakes

Forum Jump:

User Panel Messages

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