GUI doesnt open for Entry string - python

I keep getting the error time "data 'startdate_info' does not match format '%Y-%m-%d'" but it doesn't open the GUI for the data Entries. It should open a GUI for start date, end date, ticker and inspect string entry. Those strings should go into:
newtime = yf.download('ticker_info', start = 'startdate_info', end = 'enddate_info')
But for some reason I keep getting stuck on this line 55.
import yfinance as yf
import pandas as pd
import pyautogui
from tkinter import *
import keyboard
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import pyplot
screen = Tk()
screen.geometry("450x550")
startdate = StringVar()
start_date = Label(text = "Enter start date in YYYY-MM-DD format: ")
start_date.place(x = 15, y = 70)
startdate_entry = Entry(textvariable = startdate, width = "30")
startdate_entry.place(x = 15, y = 120)
enddate = StringVar()
end_date = Label(text = "Enter end date in YYYY-MM-DD format: ")
end_date.place(x = 15, y = 170)
enddate_entry = Entry(textvariable = enddate, width = "30")
enddate_entry.place(x = 15, y = 220)
tickerE = StringVar()
ticker_label = Label(text = "Ticker symbol: ")
ticker_label.place(x = 15, y = 270)
ticker = Entry(textvariable = tickerE, width = "30")
ticker.place(x = 15, y = 320)
inspectE = StringVar()
inspect_label = Label(text = "What would you like to analyze ")
inspect_label.place(x = 15, y = 270)
inspect_label = Label(text = "(Open, High, Low, Close, Adj Close, Volume)? ")
inspect_label.place(x = 15, y = 320)
inspect = Entry(textvariable = inspectE, width = "30")
inspect.place(x = 15, y = 370)
def save_info():
startdate_info = startdate.get()
enddate_info = enddate.get()
ticker_info = tickerE.get()
inspect_info = inspectE.get()
return ticker_info, inspect_info, startdate_info, enddate_info
save_info()
search = Button(screen,text = "Search", width = "30", height = "2", command = save_info, bg = "grey")
search.place(x = 14, y = 410)
ticker_info, inspect_info, startdate_info, enddate_info = save_info()
newtime = yf.download('ticker_info', start = 'startdate_info', end = 'enddate_info')
print(newtime)
def adjusted_close(ticker_info, newtime):
newtime[inspect_info].plot()
plt.xlabel("Date")
plt.ylabel(inspect_info)
plt.title(ticker_info + " " + inspect_info + " " + "Data")
plt.show()
adjusted_close(ticker_info, newtime)

You passed strings to yf.download():
newtime = yf.download('ticker_info', start = 'startdate_info', end = 'enddate_info')
You should pass the variables:
newtime = yf.download(ticker_info, start=startdate_info, end=enddate_info)
Also you should not executed the function just after creating the Entry widgets because there is nothing input yet. You should execute the function inside save_info():
def save_info():
startdate_info = startdate.get()
enddate_info = enddate.get()
ticker_info = tickerE.get()
inspect_info = inspectE.get()
print(startdate_info, enddate_info, ticker_info, inspect_info, sep=",")
newtime = yf.download(ticker_info, start=startdate_info, end=enddate_info)
print(newtime)
Below is a cut-down example based on your code:
from tkinter import *
import yfinance as yf
import matplotlib.pyplot as plt
screen = Tk()
screen.geometry("450x580")
startdate = StringVar()
start_date = Label(text="Enter start date in YYYY-MM-DD format:")
start_date.place(x=15, y=70)
startdate_entry = Entry(textvariable=startdate, width=30)
startdate_entry.place(x=15, y=120)
enddate = StringVar()
end_date = Label(text="Enter end date in YYYY-MM-DD format:")
end_date.place(x=15, y=170)
enddate_entry = Entry(textvariable=enddate, width=30)
enddate_entry.place(x=15, y=220)
tickerE = StringVar()
ticker_label = Label(text="Ticker symbol:")
ticker_label.place(x=15, y=270)
ticker = Entry(textvariable=tickerE, width=30)
ticker.place(x=15, y=320)
inspectE = StringVar()
inspect_label = Label(text="What would you like to analyze")
inspect_label.place(x=15, y=370)
inspect_label = Label(text="(Open, High, Low, Close, Adj Close, Volume)?")
inspect_label.place(x=15, y=420)
inspect = Entry(textvariable=inspectE, width=30)
inspect.place(x=15, y=470)
def save_info():
startdate_info = startdate.get()
enddate_info = enddate.get()
ticker_info = tickerE.get()
inspect_info = inspectE.get()
print(startdate_info, enddate_info, ticker_info, sep=",")
newtime = yf.download(ticker_info, start=startdate_info, end=enddate_info)
print(newtime)
# plot it
newtime[inspect_info].plot()
plt.xlabel("Date")
plt.ylabel(inspect_info)
plt.title(f"{ticker_info} {inspect_info} Data")
plt.show()
search = Button(screen, text="Search", width="30", height="2", command=save_info, bg="grey")
search.place(x=14, y=510)
screen.mainloop()

Related

Preloading Entry tkinter with Date

I am writing a program, that users enter information in which the data is then outputted into a CSV once clicked generate.
The info that needs to be entered is: Date, Time, Test Station, Serial Number, and then 3 radio button selections.
Currently, i have it so i can enter the date, time, and serial number. But i want the application to automatically update the date and time so that users don't have to enter it. I have imported a date module but no idea how to get it working within the text box.
from tkinter import *
from datetime import date
today = date.today()
d1 = today.strftime("%d/%m/%y")
def save_info():
date_info = date.get()
time_info = time.get()
serialNumber_info = serialNumber.get()
serialNumber_info = str(serialNumber_info)
print(date_info, time_info, serialNumber_info)
file = open("test.csv", "a")
file.write(date_info)
file.write(",")
file.write(time_info)
file.write(",")
file.write(serialNumber_info)
file.write("\n")
file.close()
print(" User ", date_info, " Has been registered")
date_entry.delete(0, END)
time_entry.delete(0, END)
serialNumber_entry.delete(0, END)
screen = Tk()
d1_var = StringVar(screen, d1)
screen.geometry("500x500")
screen.title("Python Form")
heading = Label(text = "Python Form", bg = "grey", fg = "black", width = "500", height = "3")
heading.pack()
date_text = Label(text = "Enter Date '(13/12/2022)' ",)
time_text = Label(text = "Enter Time '(16:45)'",)
serialNumber_text = Label(text = "Enter Serial Number ",)
date_text.place(x = 15, y = 70)
time_text.place(x = 210, y = 70)
serialNumber_text.place(x = 15, y = 210)
date = StringVar()
time = StringVar()
serialNumber = IntVar()
date_entry = Entry(textvariable = d1_var, width = "30")
time_entry = Entry(textvariable = time, width = "30")
serialNumber_entry = Entry(textvariable = serialNumber, width = "30")
date_entry.place(x = 15, y = 100)
time_entry.place(x = 210, y = 100)
serialNumber_entry.place(x = 15, y = 240)
register = Button(screen,text = "Register", width = "30", height = "2", command = save_info, bg = "grey")
register.place(x = 15, y = 400)
the text variable you define to your Entry widget should be a tkinter StringVar. You can define it after creating the Tk() and set any value you want.
screen = Tk()
d1_var = StringVar(screen, d1)
Then just change the Entry textvariable to d1_var instead:
date_entry = Entry(textvariable = d1_var, width = "30")

Date and Timestamp in python gui form

i am writing some code that appends to a CSV file. The application will be used in production and only has to be small and not complex, it should print a GUI that allows users to enter the date, time, and serial number
Currently i have a program that allows me to enter data into 3 boxes, two strings for date and time so i am able to put "/" and ":". I want to be able to use a button to get the date and time and insert in the two boxes, e.g. run the software, wants me to enter a date, i press a button and todays date appears (same with the timestamp), or possible to automatically fill the box with the date and time.
As i mentioned before, currently i have the code so i enter a string in "12/12/2022" and similar with timestamp just so i can get the formatting right. But here is the code.
from tkinter import *
def save_info():
date_info = date.get()
time_info = time.get()
serialNumber_info = serialNumber.get()
serialNumber_info = str(serialNumber_info)
print(date_info, time_info, serialNumber_info)
file = open("test.csv", "a")
file.write(date_info)
file.write(",")
file.write(time_info)
file.write(",")
file.write(serialNumber_info)
file.write("\n")
file.close()
print(" User ", date_info, " Has been registered")
date_entry.delete(0, END)
time_entry.delete(0, END)
serialNumber_entry.delete(0, END)
screen = Tk()
screen.geometry("500x500")
screen.title("Python Form")
heading = Label(text = "Python Form", bg = "grey", fg = "black", width = "500", height = "3")
heading.pack()
date_text = Label(text = "Date * ",)
time_text = Label(text = "Time * ",)
serialNumber_text = Label(text = "Serial Number * ",)
date_text.place(x = 15, y = 70)
time_text.place(x = 15, y = 140)
serialNumber_text.place(x = 15, y = 210)
date = StringVar()
time = StringVar()
serialNumber = IntVar()
date_entry = Entry(textvariable = date, width = "30")
time_entry = Entry(textvariable = time, width = "30")
serialNumber_entry = Entry(textvariable = serialNumber, width = "30")
date_entry.place(x = 15, y = 100)
time_entry.place(x = 15, y = 180)
serialNumber_entry.place(x = 15, y = 240)
register = Button(screen,text = "Register", width = "30", height = "2", command = save_info, bg = "grey")
register.place(x = 15, y = 400)
You can use datetime module to get the current time to fill the date and time entry boxes:
...
from datetime import datetime
...
def fill_datetime():
# get current date and time
now = datetime.now()
# fill date
date.set(now.strftime("%d/%m/%Y"))
# fill time
time.set(now.strftime("%T"))
datetime_button = Button(screen, text="Fill Date and Time", width=30, height=2, command=fill_datetime, bg="grey")
datetime_button.place(x=15, y=300)
...

Traceback (most recent call last): _tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack in python

I have a problem with my code in Python
I want to transfer the data after entering it into the excel file
But I get an error with the title: Traceback (most recent call last):
File "C:\Users\yasen\Desktop\برمجة\graphics\main11.py", line 60, in
firstname_text = Label(text = "الاسم الاول * ",).grid(row=0)
File "C:\Users\yasen\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", line 2522, in grid_configure
self.tk.call(
_tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack
my code
from tkinter import *
import pandas as pd
def send_info():
path = 'Registers.form.xlsx'
df1 = pd.read_excel(path)
SeriesA = df1['firstname']
SeriesB = df1['secondname']
SeriesC = df1['thirdname']
SeriesD = df1['age']
SeriesE = df1['phonenumber']
SeriesF = df1['Departmentname']
SeriesG = df1['familymembers']
SeriesH = df1['bookingdate']
A = pd.Series(firstname.get)
B = pd.Series(secondname.get)
C = pd.Series(thirdname.get)
D = pd.Series(age.get)
E = pd.Series(phonenumber.get)
F = pd.Series(Departmentname.get)
G = pd.Series(familymembers.get)
H = pd.Series(bookingdate.get)
SeriesA = SeriesA.append(A)
SeriesB = SeriesA.append(B)
SeriesC = SeriesA.append(C)
SeriesD = SeriesA.append(D)
SeriesE = SeriesA.append(E)
SeriesF = SeriesA.append(F)
SeriesG = SeriesA.append(G)
SeriesH = SeriesA.append(H)
df2 = pd.DataFrame({"firstname": SeriesA, "secondnamer": SeriesB, "thirdname": SeriesC, "age": SeriesD, "phonenumber": SeriesE, "Departmentname": SeriesF, "familymembers": SeriesG, "bookingdate": SeriesH})
df2.to_excel(path, index=False)
firstname_entry.delete(0, END)
secondname_entry.delete(0, END)
thirdname_entry.delete(0, END)
age_entry.delete(0, END)
phonenumber_entry.delete(0, END)
Departmentname_entry.delete(0, END)
familymembers_entry.delete(0, END)
bookingdate_entry.delete(0, END)
screen = Tk()
screen.geometry("1080x1080")
screen.title("مديرية شؤون البطاقة الوطنية")
welcome_text = Label(text="أهلا وسهلا بكم في الحجز الالكتروني للبطاقة الموحدة ", fg="white", bg="green",height=2 ,width=1080)
welcome_text.pack()
firstname_text = Label(text = "الاسم الاول * ",).grid(row=0)
secondname_text = Label(text = "الاسم الثاني * ",).grid(row=1)
thirdname_text = Label(text = "الاسم الثالث * ",).grid(row=2)
age_text = Label(text = "العمر * ",).grid(row=3)
phonenumber_text = Label(text = "رقم الهاتف * ",).grid(row=4)
Departmentname_text = Label(text = "اسم دائرة الاحوال المدنية * ",).grid(row=5)
familymembers_text = Label(text = "عدد افراد الاسرة * ",).grid(row=6)
bookingdate_text = Label(text = "موعد تاريخ الحجز المطلوب * ",).grid(row=7)
firstname_text.place(x = 540, y = 70)
secondname_text.place(x = 540, y = 130)
thirdname_text.place(x = 540, y = 190)
age_text.place(x = 540, y = 250)
phonenumber_text.place(x = 540, y = 310)
Departmentname_text.place(x = 540, y = 370)
familymembers_text.place(x = 540, y = 430)
bookingdate_text.place(x = 540, y = 490)
firstname = StringVar()
secondname = StringVar()
thirdname = StringVar()
age = StringVar()
phonenumber = StringVar()
Departmentname = StringVar()
familymembers = StringVar()
bookingdate = StringVar()
firstname_entry = Entry(textvariable = firstname, width = "40")
secondname_entry = Entry(textvariable = secondname, width = "40")
thirdname_entry = Entry(textvariable = thirdname, width = "40")
age_entry = Entry(textvariable = age, width = "40")
phonenumber_entry = Entry(textvariable = phonenumber, width = "40")
Departmentname_entry = Entry(textvariable = Departmentname, width = "40")
familymembers_entry = Entry(textvariable = familymembers, width = "40")
bookingdate_entry = Entry(textvariable = bookingdate, width = "40")
firstname_entry.place(x = 450, y = 100)
secondname_entry.place(x = 450, y = 160)
thirdname_entry.place(x = 450, y = 220)
age_entry.place(x = 450, y = 280)
phonenumber_entry.place(x = 450, y = 340)
Departmentname_entry.place(x = 450, y = 400)
familymembers_entry.place(x = 450, y = 460)
bookingdate_entry.place(x = 450, y = 520)
firstname_entry.grid(row=0,column=1)
secondname_entry.grid(row=1,column=1)
thirdname_entry.grid(row=2,column=1)
age_entry.grid(row=3,column=1)
phonenumber_entry.grid(row=4,column=1)
Departmentname_entry.grid(row=5,column=1)
familymembers_entry.grid(row=6,column=1)
bookingdate_entry.grid(row=7,column=1)
register = Button(screen,text = "Register", width = "60", height = "2", command = send_info, bg = "grey").grid(row=3,column=1, pady=4)
register.place(x = 360, y = 600)
screen.mainloop ()
As I just said on FB - you cant miy .place, .pack. and .grid
from tkinter import *
import pandas as pd
def send_info():
path = 'Registers.form.xlsx'
df1 = pd.read_excel(path)
SeriesA = df1['firstname']
SeriesB = df1['secondname']
SeriesC = df1['thirdname']
SeriesD = df1['age']
SeriesE = df1['phonenumber']
SeriesF = df1['Departmentname']
SeriesG = df1['familymembers']
SeriesH = df1['bookingdate']
A = pd.Series(firstname.get)
B = pd.Series(secondname.get)
C = pd.Series(thirdname.get)
D = pd.Series(age.get)
E = pd.Series(phonenumber.get)
F = pd.Series(Departmentname.get)
G = pd.Series(familymembers.get)
H = pd.Series(bookingdate.get)
SeriesA = SeriesA.append(A)
SeriesB = SeriesA.append(B)
SeriesC = SeriesA.append(C)
SeriesD = SeriesA.append(D)
SeriesE = SeriesA.append(E)
SeriesF = SeriesA.append(F)
SeriesG = SeriesA.append(G)
SeriesH = SeriesA.append(H)
df2 = pd.DataFrame(
{"firstname": SeriesA, "secondnamer": SeriesB, "thirdname": SeriesC, "age": SeriesD, "phonenumber": SeriesE,
"Departmentname": SeriesF, "familymembers": SeriesG, "bookingdate": SeriesH})
df2.to_excel(path, index=False)
firstname_entry.delete(0, END)
secondname_entry.delete(0, END)
thirdname_entry.delete(0, END)
age_entry.delete(0, END)
phonenumber_entry.delete(0, END)
Departmentname_entry.delete(0, END)
familymembers_entry.delete(0, END)
bookingdate_entry.delete(0, END)
screen = Tk()
screen.geometry("1080x1080")
screen.title("مديرية شؤون البطاقة الوطنية")
welcome_text = Label(text="أهلا وسهلا بكم في الحجز الالكتروني للبطاقة الموحدة ", fg="white", bg="green", height=2,
width=1080)
firstname_text = Label(text="الاسم الاول * ", )
secondname_text = Label(text="الاسم الثاني * ", )
thirdname_text = Label(text="الاسم الثالث * ", )
age_text = Label(text="العمر * ", )
phonenumber_text = Label(text="رقم الهاتف * ", )
Departmentname_text = Label(text="اسم دائرة الاحوال المدنية * ", )
familymembers_text = Label(text="عدد افراد الاسرة * ", )
bookingdate_text = Label(text="موعد تاريخ الحجز المطلوب * ", )
firstname = StringVar()
firstname.set("Test")
secondname = StringVar()
thirdname = StringVar()
age = StringVar()
phonenumber = StringVar()
Departmentname = StringVar()
familymembers = StringVar()
bookingdate = StringVar()
firstname_entry = Entry(textvariable=firstname, width=40)
secondname_entry = Entry(textvariable=secondname, width=40)
thirdname_entry = Entry(textvariable=thirdname, width=40)
age_entry = Entry(textvariable=age, width=40)
phonenumber_entry = Entry(textvariable=phonenumber, width=40)
Departmentname_entry = Entry(textvariable=Departmentname, width=40)
familymembers_entry = Entry(textvariable=familymembers, width=40)
bookingdate_entry = Entry(textvariable=bookingdate, width=40)
firstname_entry.grid(row=0, column=1)
secondname_entry.grid(row=1, column=1)
thirdname_entry.grid(row=2, column=1)
age_entry.grid(row=3, column=1)
phonenumber_entry.grid(row=4, column=1)
Departmentname_entry.grid(row=5, column=1)
familymembers_entry.grid(row=6, column=1)
bookingdate_entry.grid(row=7, column=1)
'''register = Button(screen, text="Register", width="60", height="2", command=send_info, bg="grey").grid(row=3, column=1,
pady=4)
register.place(x=360, y=600)'''
screen.mainloop()
This is what you want, like this. You see Label on green background and gray button. I remove all widgets grid() because of that saying cannot use geometry manager grid inside . which already has slaves managed by pack
Code:
from tkinter import *
import pandas as pd
def send_info():
path = 'Registers.form.xlsx'
df1 = pd.read_excel(path)
SeriesA = df1['firstname']
SeriesB = df1['secondname']
SeriesC = df1['thirdname']
SeriesD = df1['age']
SeriesE = df1['phonenumber']
SeriesF = df1['Departmentname']
SeriesG = df1['familymembers']
SeriesH = df1['bookingdate']
A = pd.Series(firstname.get)
B = pd.Series(secondname.get)
C = pd.Series(thirdname.get)
D = pd.Series(age.get)
E = pd.Series(phonenumber.get)
F = pd.Series(Departmentname.get)
G = pd.Series(familymembers.get)
H = pd.Series(bookingdate.get)
SeriesA = SeriesA.append(A)
SeriesB = SeriesA.append(B)
SeriesC = SeriesA.append(C)
SeriesD = SeriesA.append(D)
SeriesE = SeriesA.append(E)
SeriesF = SeriesA.append(F)
SeriesG = SeriesA.append(G)
SeriesH = SeriesA.append(H)
df2 = pd.DataFrame({"firstname": SeriesA, "secondnamer": SeriesB, "thirdname": SeriesC, "age": SeriesD, "phonenumber": SeriesE, "Departmentname": SeriesF, "familymembers": SeriesG, "bookingdate": SeriesH})
df2.to_excel(path, index=False)
firstname_entry.delete(0, END)
secondname_entry.delete(0, END)
thirdname_entry.delete(0, END)
age_entry.delete(0, END)
phonenumber_entry.delete(0, END)
Departmentname_entry.delete(0, END)
familymembers_entry.delete(0, END)
bookingdate_entry.delete(0, END)
screen = Tk()
screen.geometry("1080x1080")
screen.title("مديرية شؤون البطاقة الوطنية")
welcome_text = Label(text="أهلا وسهلا بكم في الحجز الالكتروني للبطاقة الموحدة ", fg="white", bg="green",height=2 ,width=1080)
welcome_text.pack()
firstname_text = Label(text="الاسم الاول * ")
secondname_text = Label(text="الاسم الثاني * ")
thirdname_text = Label(text="الاسم الثالث * ")
age_text = Label(text="العمر * ")
phonenumber_text = Label(text="رقم الهاتف * ")
Departmentname_text = Label(text="اسم دائرة الاحوال المدنية * ")
familymembers_text = Label(text="عدد افراد الاسرة * ")
bookingdate_text = Label(text="موعد تاريخ الحجز المطلوب * ")
firstname_text.place(x=540, y=70)
secondname_text.place(x=540, y=130)
thirdname_text.place(x=540, y=190)
age_text.place(x=540, y=250)
phonenumber_text.place(x=540, y=310)
Departmentname_text.place(x=540, y=370)
familymembers_text.place(x=540, y=430)
bookingdate_text.place(x=540, y=490)
firstname = StringVar()
secondname = StringVar()
thirdname = StringVar()
age = StringVar()
phonenumber = StringVar()
Departmentname = StringVar()
familymembers = StringVar()
bookingdate = StringVar()
firstname_entry = Entry(textvariable=firstname, width="40")
secondname_entry = Entry(textvariable=secondname, width="40")
thirdname_entry = Entry(textvariable=thirdname, width="40")
age_entry = Entry(textvariable=age, width="40")
phonenumber_entry = Entry(textvariable=phonenumber, width="40")
Departmentname_entry = Entry(textvariable=Departmentname, width="40")
familymembers_entry = Entry(textvariable=familymembers, width="40")
bookingdate_entry = Entry(textvariable=bookingdate, width="40")
firstname_entry.place(x=450, y=100)
secondname_entry.place(x=450, y=160)
thirdname_entry.place(x=450, y=220)
age_entry.place(x=450, y=280)
phonenumber_entry.place(x=450, y=340)
Departmentname_entry.place(x=450, y=400)
familymembers_entry.place(x=450, y=460)
bookingdate_entry.place(x= 450, y=520)
register = Button(screen,text="Register", width="60", height="2", command=send_info, bg="grey")
register.place(x=360, y=600)
screen.mainloop()
Result:
This is because Tkinter doesn't allow to use more than one placement of a widget in the whole script. So, if you want to run your code, then you'll have to remove either the grid() function everywhere and replace it with the pack() function or the remove the pack() function and replace it with the grid() function.

How do I make this python GUI run this executable?

I'm trying to make a basic gui menu option that will run my stated exe (hurl), but it won't. Here is my code:
from tkinter import *
import os
root = Tk()
root.geometry('350x150')
root.title("hurler")
photo = PhotoImage(file = "Logo_Image.png")
root.iconphoto(False, photo)
entry_text = Label(text = "Number of posts you wish to automate (between 1-12) * ")
entry_text.place(x = 15, y = 10)
num = StringVar()
time_entry = Entry(textvariable = num, width = "10")
time_entry.place(x = 15, y = 40)
def action():
if num == '1':
os.system(".\hurl\hurl.exe")
register = Button(root,text = "Make", width = "10", height = "2", command = action, bg = "lightblue")
register.place(x = 15, y = 70)
root.mainloop()
I'm not the most experienced at this, so any feedback helps.
How do I get option 1 to run this exe? Thanks.
so these are the improvements, should work now:
from tkinter import *
import os
root = Tk()
root.geometry('350x150')
root.title("hurler")
# photo = PhotoImage(file = "Logo_Image.png")
# root.iconphoto(False, photo)
entry_text = Label(text = "Number of posts you wish to automate (between 1-12) * ")
entry_text.place(x = 15, y = 10)
num = StringVar()
time_entry = Entry(textvariable = num, width = "10")
time_entry.place(x = 15, y = 40)
def action():
global num
num = num.get()
if num == '1':
os.startfile('https://www.google.com')
num = StringVar()
register = Button(root,text = "Make", width = "10", height = "2", command = action, bg = "lightblue")
register.place(x = 15, y = 70)
root.mainloop()
the changes were made here:
def action():
global num
num = num.get()
if num == '1':
os.startfile('https://www.google.com')
num = StringVar()
also should work with the os.system thingy

py2exe not working - flashing console and closes

EXE won't open. I have tried everything I found online.
When I run the exe the console opens for a few seconds and then closes.
How can I make this .py executable and have my .txt output?
from tkinter import *
import time, os, fnmatch, shutil
screen = Tk()
screen.geometry("600x450")
screen.configure(background='azure')
screen.title("M")
t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
BACKUP_NAME = ("backup-" + timestamp)
heading = Label(text = "Mr", font=(None, 15), bg = "lightblue", fg = "black", width = "500", height = "3")
heading.pack()
firstname_text = Label(text = "Name/ * ", bg = "azure",)
lastname_text = Label(text = "Usagel* ", bg = "azure",)
material_text = Label(text = "M * ", bg = "azure",)
age_text = Label(text = "How * ", bg = "azure",)
firstname_text.place(x = 15, y = 80)
lastname_text.place(x = 15, y = 140)
material_text.place(x = 15, y = 210)
age_text.place(x = 15, y = 260)
firstname = StringVar()
lastname = StringVar()
material = StringVar()
age = StringVar()
firstname_entry = Entry(textvariable = firstname, width = "30")
lastname_entry = Entry(textvariable = lastname, width = "30")
material_entry = Entry(textvariable = material, width = "30")
age_entry = Entry(textvariable = age, width = "30")
firstname_entry.place(x = 15, y = 100)
lastname_entry.place(x = 15, y = 170)
material_entry.place(x = 15, y = 240)
age_entry.place(x = 15, y = 290)
register = Button(screen,text = "Submit", font=(None, 10), width = "30", height = "2", command = save_info, bg = "lime green")
register.place(x = 15, y = 320)

Categories

Resources