0

I am totally new in python GUI and Tkinter. Now i want an entry field where i can change the value or time of self.hide when i will execute this code. that means self.hide value will change from Entry field. In this code this value is statically set to 1 minute. need help from experts.

import Tkinter as Tk
import time
import tkMessageBox

class Window:
   def __init__(self):
      self.root = None
      self.hide = 1 #minutes
      self.show = 3 #seconds

   def close(self):
      self.root.destroy()
      return

   def new(self):
      self.root = Tk.Tk()
      self.root.overrideredirect(True)
      self.root.geometry("{0}x{1}+0+0".format(self.root.winfo_screenwidth(), self.root.winfo_screenheight()))
      self.root.configure(bg='black')
    Tk.Label(self.root, text='Hello', fg='white', bg='black', font=('Helvetica', 30)).place(anchor='center', relx=0.5, rely=0.5)
    #tkMessageBox.showinfo("Notification", "Your time is up. Time to do next job. . .")
    Tk.Button(text = 'Close', command = self.close).pack()

      self.root.after(self.show*1000, self.pp)

   def pp(self):
       if self.root:
          self.root.destroy()
          time.sleep(self.hide*60)
          self.new()
          self.root.mainloop()
          return

Window().pp()

2 Answers2

0

To summarise:

  1. Instead of using the sleep function, use the after function. This will not freeze the GUI.

  2. Set the "wait" time of the after function self.Entry.get(). This will collect the info you have put into the Entry.

For more info, look at these links. People smarter than myself give a very clear explication on how to use the functions. Tkinter, executing functions over time tkinter: how to use after method

Community
  • 1
  • 1
Stijn Van Daele
  • 285
  • 1
  • 14
0

Try This. It may help you.

from Tkinter import *
import time


root = Tk()

def close():
   root.destroy()

def show():
   root.deiconify()
   button.config(text = 'Close', command = close)
   root.after(1000, hide)

def hide():

   root.withdraw()
   time_to_sleep = set_time_to_sleep.get()
   time_to_sleep = float(time_to_sleep)
   #print time_to_sleep
   time.sleep(time_to_sleep)
   show()



set_time_to_sleep = Entry(root)
set_time_to_sleep.pack(side=LEFT)
button = Button(text = 'Set Time', command = hide)
button.pack()

root.mainloop()
kazinayem2011
  • 348
  • 6
  • 20