Reputation: 21
i had to do a simply program in python for raspberry a simply form with 16 buttons (loginuser1 loginuser2 etc) when user1 press the loginuser1 button it will appear an inputbox and he can enter his password if password is corrected the program will launch another .py how can i do?
import tkinter as tk
from tkinter import font
import subprocess, os
import sys
global e, master, win, b
win = tk.Tk()
myFont = font.Font(family = 'Helvetica', size = 12, weight = 'bold')
master = tk.Tk()
e = tk.Entry(win)
create = [sys.executable, 'ciao.py']
nomescript = "ciao.py"
def LoginUser1():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback1)
b.grid()
def callback1():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser2():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback2)
b.grid()
def callback2():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser3():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback3)
b.grid()
def callback3():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser4():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback4)
b.grid()
def callback4():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser5():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback5)
b.grid()
def callback5():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser6():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback6)
b.grid()
def callback6():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser7():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback7)
b.grid()
def callback7():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser8():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback8)
b.grid()
def callback8():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser9():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback9)
b.grid()
def callback9():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser10():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback10)
b.grid()
def callback10():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser11():
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback11)
b.grid()
def callback11():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser12():
e.grid()
e.focus_set()
b = Button(win, text = "OK", width = 10, command = callback12)
b.grid()
def callback12():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser13():
e.grid()
e.focus_set()
b = Button(win, text = "OK", width = 10, command = callback13)
b.grid()
def callback13():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser14():
e.grid()
e.focus_set()
b = Button(win, text = "OK", width = 10, command = callback14)
b.grid()
def callback14():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser15():
e.grid()
e.focus_set()
b = Button(win, text = "OK", width = 10, command = callback15)
b.grid()
def callback15():
if (e.get() == "prova1"):
subprocess.call(create)
def LoginUser16():
e.grid()
e.focus_set()
b = Button(win, text = "OK", width = 10, command = callback16)
b.grid()
def callback16():
if (e.get() == "prova1"):
subprocess.call(create)
win.title("Prova")
win.geometry('800x480')
btn1 = tk.Button(win, text = "User1", font = myFont, command = LoginUser1, height = 1 , width = 18)
btn1.grid(row=1,column=2)
btn2 = tk.Button(win, text = "User2", font = myFont, command = LoginUser2, height = 1, width = 18 )
btn2.grid(row=2,column=2)
btn3 = tk.Button(win, text = "User3", font = myFont, command = LoginUser3, height = 1, width =18 )
btn3.grid(row=3,column=2)
btn4 = tk.Button(win, text = "User4", font = myFont, command = LoginUser4, height = 1, width =18 )
btn4.grid(row=4,column=2)
btn5 = tk.Button(win, text = "User5", font = myFont, command = LoginUser5, height = 1, width =18 )
btn5.grid(row=1,column=3)
btn6 = tk.Button(win, text = "User6", font = myFont, command = LoginUser6, height = 1, width =18 )
btn6.grid(row=2,column=3)
btn7 = tk.Button(win, text = "User7", font = myFont, command = LoginUser7, height = 1, width =18 )
btn7.grid(row=3,column=3)
btn8 = tk.Button(win, text = "User8", font = myFont, command = LoginUser8, height = 1, width =18 )
btn8.grid(row=4,column=3)
btn9 = tk.Button(win, text = "User9", font = myFont, command = LoginUser9, height = 1, width =18 )
btn9.grid(row=10,column=2)
btn10 = tk.Button(win, text = "User10", font = myFont, command = LoginUser10, height = 1, width = 18 )
btn10.grid(row=11,column=2)
btn11 = tk.Button(win, text = "User11", font = myFont, command = LoginUser11, height = 1, width =18 )
btn11.grid(row=12,column=2)
btn12 = tk.Button(win, text = "User12", font = myFont, command = LoginUser12, height = 1, width =18 )
btn12.grid(row=13,column=2)
btn13 = tk.Button(win, text = "User13", font = myFont, command = LoginUser13, height = 1, width =18 )
btn13.grid(row=10,column=3)
btn14 = tk.Button(win, text = "User14", font = myFont, command = LoginUser14, height = 1, width =18 )
btn14.grid(row=11,column=3)
btn15 = tk.Button(win, text = "User15", font = myFont, command = LoginUser15, height = 1, width =18 )
btn15.grid(row=12,column=3)
btn16 = tk.Button(win, text = "User16", font = myFont, command = LoginUser16, height = 1, width =18 )
btn16.grid(row=13,column=3)
win.rowconfigure(16, {'minsize': 10})
win.columnconfigure(4, {'minsize': 10})
win.mainloop()
i can't delete the entry and button for another operations it should delete the button and the entry for the next inputs.
Upvotes: 0
Views: 27
Reputation: 142774
global
doesn't create global variables - all variables created outside functions are automatically global.
You have to use global
inside function but only if you want to assing new value ie. b = ...
def LoginUser1():
global b
e.grid()
e.focus_set()
b = tk.Button(win, text = "OK", width = 10, command = callback1)
b.grid()
To remove widget you have to use destroy()
b.destroy()
but after that you would have to create againg widget before you put it in grid
b = Button(...)
b.grid()
or you can remove from window
b.grid_forget() # .grid_remove()
and then it still exists so you can use only
b.grid()
to show it again in window
Upvotes: 1