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")
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)
...
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.
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
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)