I am trying to write a simple program that runs the console command for automated delayed shutdown on Windows: "shutdown -s -t num", where num is the delay in seconds before the automated shutdown occurs. By hardcoding a predefined number there in the Python command os.system("cmd /c shutdown -s -t 1234") it works just fine. Then I created a Tkinter window with an entry widget, and a button to confirm. However, when trying to get data from the entry widget, something strange keeps happening.
Regardless of what is actually stored there, I always get "<bound method StringVar.get of <tkinter.StringVar object at 0x03DCE160>>". I tried to solve this by passing the data in the StringVar to a regular variable, but that just led to where I am now. When I try to add the string via a variable to the command, I get "TypeError: can only concatenate str (not "method") to str". My minimum code is as follows:
from tkinter import *
import os
class Shutdown_Timer(Frame):
def __init__(self):
Frame.__init__(self)
self.master.geometry("200x27")
self.grid()
self.time = StringVar()
self.time.set("0")
self.time_get = "0"
self.Input = Entry(self)
self.Input.grid(row = 0, column = 1)
self.submit = Button(self, text = "Start Timer", command = self.submit_time)
self.submit.grid(row = 0, column = 2)
def submit_time(self):
self.time.set(self.Input.get)
self.time_get = self.time.get
#Gives first error about bound method
print(self.time_get)
#Gives second error (TypeError)
print("cmd /c shutdown -s -t " + self.time_get)
#os.system("cmd /c shutdown -s -t " + self.time_get)
frame01 = Shutdown_Timer()
frame01.mainloop
Changing it to
def submit_time(self):
self.time_get = self.Input.get
print(self.time_get)
print("cmd /c shutdown -s -t " + self.time_get)
to pull the Entry directly into the normal variable instead gives "<bound method Entry.get of <tkinter.Entry object .!shutdown_timer.!entry>>" and then the same error about not concatenating a method and a string.