Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter
#1
HI guys
I'm new with python and tkinter trying to make my first project.
I have a few questions:
1. how to return to the window menu using a button in a little window created by one of those menu options without loosing variables obtained in that window?.
2. why using the "entry" widget, I can't see the cursor of the key I press?

thanks
Reply
#2
please show your code.
Reply
#3
from tkinter import *
#from tkinter import ttk

def donothing():
    filewin = Toplevel(root)
    button = Button(filewin, text="Do nothing button")
    button.pack()
 
def close_window(root): 
    window.destroy()
 
def ending_session():
   print("==================================================")
   print("Closing session.....")
   print("\n")
   print("...Bye")
   print("\n")
   print("==================================================")
   from tkinter import messagebox
   messagebox.showinfo(message='Have a good day')
    
def new_session():
   CDU_newsession = Tk()
   CDU_newsession.geometry('460x140+170+80')
#   CDU_session.title("New Test Session")
   CDU_newsession.overrideredirect(1)  #it removes the top badge
   print("==================================================")
   print("Test Procedure")
   print("Liquid Crystal Display Control Display Unit")
   print("174101  Model 2584")
   print("ATA 34-61-14, ATLAS Test Specification 552353-10-01\n")
   Label(CDU_newsession, text ="        Work Order:",font = ('Arial', 12, "bold")).grid(row=1, column=0, sticky='E')
   Label(CDU_newsession, text ="       Part Number:",font = ('Arial', 12, "bold")).grid(row=2, column=0, sticky='E')
   Label(CDU_newsession, text ="     Serial Number:",font = ('Arial', 12, "bold")).grid(row=3, column=0, sticky='E')
   Label(CDU_newsession, text ="     Starting Date:",font = ('Arial', 12, "bold")).grid(row=4, column=0, sticky='E')
   Label(CDU_newsession, text ="        Technician:",font = ('Arial', 12, "bold")).grid(row=5, column=0, sticky='S')

   UUT_WOnew = Entry(CDU_newsession, width=15)
   UUT_PNnew = Entry(CDU_newsession, width=15)
   UUT_SNnew = Entry(CDU_newsession, width=15)
   UUT_SDnew = Entry(CDU_newsession, width=15)
   UUT_Technew = Entry(CDU_newsession, width=20)

   UUT_WOnew.grid(row=1, column=1, sticky='W')
   UUT_PNnew.grid(row=2, column=1, sticky='W')
   UUT_SNnew.grid(row=3, column=1, sticky='W')
   UUT_SDnew.grid(row=4, column=1, sticky='W')
   UUT_Technew.grid(row=5, column=1, sticky='W')
   
   Button(CDU_newsession, text ="Test Procedure",font = ('Arial', 12, "bold"), command = test_procedure).grid(row=15 , column=2, sticky='W', padx=2)

   
def open_session():
   CDU_opensession = Tk()
   CDU_opensession.geometry('405x85+200+80')
#   CDU_session.title("New Test Session")
   CDU_opensession.overrideredirect(1)  #it removes the top badge
   Label(CDU_opensession, text ="Work Order:",font = ('Arial', 12, "bold")).grid(row=1, column=0, sticky='E')
   UUT_WOopen = Entry(CDU_opensession, width=15)
   UUT_WOopen.grid(row=1, column=1)
   Button(CDU_opensession, text =" View  Report ",font = ('Arial', 12, "bold"), command = ending_session).grid(row=10, column=0, sticky='W', padx=2)
   Button(CDU_opensession, text =" Print Report ",font = ('Arial', 12, "bold"), command = ending_session).grid(row=10, column=1, sticky='W', padx=2)
   Button(CDU_opensession, text =" Send  Report ",font = ('Arial', 12, "bold"), command = ending_session).grid(row=10, column=2, sticky='W', padx=2)
   Button(CDU_opensession, text =" Return ",font = ('Arial', 12, "bold"), command = ending_session).grid(row=16, column=1, sticky='S', padx=2)

   UUT_WOopen.focus()

def test_procedure():
   CDU_test = Tk()
   CDU_test.geometry('500x268+48+225')
   CDU_test.title("CDU Acceptance Test Procedure")
# create file with name = WO number
   print("==================================================")
   print("Test Procedure")
   print("Liquid Crystal Display Control Display Unit")
   print("174101  Model 2584")
   print("ATA 34-61-14, ATLAS Test Specification 552353-10-01\n")
   Label(CDU_test, text ="    Test.1:",font = ('Arial', 14, "bold")).grid(row=0, column=0, sticky='W') 
   Label(CDU_test, text ="Power supply Test.",font = ('Arial', 14, "bold")).grid(row=0, column=1, sticky='W')
   Label(CDU_test, text ="---------------------------------------------------------------",font = ('Arial', 12, "bold")).grid(row=3, column=1, sticky='W')
   Label(CDU_test, text ="This test checks the voltages of the power",font = ('Arial', 12, "bold")).grid(row=5, column=1, sticky='W')
   Label(CDU_test, text ="supplies. The DC voltages and annunciator",font = ('Arial', 12, "bold")).grid(row=6, column=1, sticky='W')
   Label(CDU_test, text ="outputs of the power supply are sampled",font = ('Arial', 12, "bold")).grid(row=7, column=1, sticky='W')
   Label(CDU_test, text ="and converted to digital equivalent,",font = ('Arial', 12, "bold")).grid(row=8, column=1, sticky='W')
   Label(CDU_test, text ="that are output to the test station.", font = ('Arial', 12, "bold")).grid(row=9, column=1, sticky='W')
   Label(CDU_test, text ="  ",font = ('Arial', 12, "bold")).grid(row=10, column=1, sticky='W')
   Label(CDU_test, text ="  ",font = ('Arial', 12, "bold")).grid(row=11, column=1, sticky='W')
   Label(CDU_test, text ="  ",font = ('Arial', 12, "bold")).grid(row=12, column=1, sticky='W')
   Label(CDU_test, text ="  ",font = ('Arial', 12, "bold")).grid(row=13, column=1, sticky='W')


   skip = Button(CDU_test, text=" Skip ", font = ('Arial', 12, "bold"), command = donothing).grid(row=14, column=1, sticky='E', padx=2)
   print("Test Step 1 =========================\n")

   enter = Button(CDU_test, text="Enter", font = ('Arial', 12, "bold"), command = close_window).grid(row=14, column=2, sticky='W', padx=2)
   print("Test Step 2 =========================\n")

   print("Test Step 3 =========================\n")
   print("Test Step 4 =========================\n")
   print("Test Step 5 =========================\n")
   
   
def window(main):
    main.title('ATA: 34-61-14,   Liquid Crystal Display Control Display Unit')

root = Tk()
root.geometry('800x480+0+0')
root.title('Liquid Crystal Display Control Display Unit (LCDCDU)     ATA: 34-61-14')   
labelfont = ('Arial', 11, 'bold')

# Canvas =================================================================================================
canvas_width = 790
canvas_height = 470
canvas = Canvas(root,
                width=canvas_width,
                height=canvas_height)
canvas.grid(row=1, column=0, rowspan=1, columnspan=2, sticky='n')
img = PhotoImage(file="CDU.gif")
canvas.create_image(7,8, anchor=NW, image=img)
#=========================================================================================================


# Menu ===================================================================================================

menubar = Menu(root)                    #   menu bar 

sessionmenu = Menu(menubar, tearoff=0)
sessionmenu.add_command(label="New",font = ('Arial', 11, "bold"), command=new_session)
sessionmenu.add_command(label="Open",font = ('Arial', 11, "bold"), command=open_session)  
sessionmenu.add_command(label="Save",font = ('Arial', 11, "bold"), command=donothing)
sessionmenu.add_command(label="Save as...",font = ('Arial', 11, "bold"), command=donothing)
sessionmenu.add_command(label="Close",font = ('Arial', 11, "bold"), command=ending_session)
#sessionmenu.add_separator()
#sessionmenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="Session", font = ('Arial', 11, "bold"), menu=sessionmenu)

helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help Index", font = ('Arial', 11, "bold"), command=donothing)
helpmenu.add_command(label="About...", font = ('Arial', 11, "bold"), command=donothing)
menubar.add_cascade(label="Help", font = ('Arial', 11, "bold"), menu=helpmenu)


#Label(root, text="").grid(row=12, column=14, sticky='e')
#=====================================================================================================

root.config(menu=menubar)
window(root)
root.mainloop()
Reply
#4
(Sep-11-2020, 04:41 PM)Larz60+ Wrote: please show your code.

did you see the code?
best regards
Reply
#5
why are you running separate sessions?
there is a zombie being created by one of them.
Reply
#6
The most obvious mistake is that you're creating separate Tkinter sessions with Tk(). There's probably other things wrong with your code as well, but if you want to be creating several windows, you should use the top level widget.
Reply
#7
(Sep-15-2020, 03:38 PM)Knight18 Wrote: The most obvious mistake is that you're creating separate Tkinter sessions with Tk(). There's probably other things wrong with your code as well, but if you want to be creating several windows, you should use the top level widget.

separated Tkinter sessions with Tk()?

any other recommendation beside Top Level Widgets ?
thanks

(Sep-15-2020, 02:49 PM)Larz60+ Wrote: why are you running separate sessions?
there is a zombie being created by one of them.

separate sessions?
Reply
#8
Before you it can create any windows Tk has to do a bunch of initialization stuff. The initialization stuff happens when you call tkinter.Tk(). Each executable should only call tkinter.Tk() once, and it has to be the first call to the tkinter module.

You probably want to make multiple windows. As Knight18 mentions you can do this by making multiple top level widgets (tkinter has a call for making a top level widget), or you can just create frames that do not have a parent and the window manager will supply a parent (make a window).
Reply
#9
(Sep-16-2020, 06:23 PM)deanhystad Wrote: Before you it can create any windows Tk has to do a bunch of initialization stuff. The initialization stuff happens when you call tkinter.Tk(). Each executable should only call tkinter.Tk() once, and it has to be the first call to the tkinter module.

You probably want to make multiple windows. As Knight18 mentions you can do this by making multiple top level widgets (tkinter has a call for making a top level widget), or you can just create frames that do not have a parent and the window manager will supply a parent (make a window).

any example I can use for reference?
I'm just staring with tkinter
thanks
Reply
#10
If you are just starting you should look for a tkinter tutorial that makes multiple windows.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020