juliolop
Posts: 20
Joined: Thu Sep 27, 2018 4:33 pm

menubar fonts

Fri Dec 14, 2018 2:16 pm

hi I have this code to run in an LCD display 5"
that's the reason of dimensions 800x480

the problem is when I call the function test_procedure() the new windows show my menu but I can't change font and sizes in the main menu
I got it in pull downs menus but not in the main menu
what do i have to do?

code...



#imports ===========================================================================================
from tkinter import *
from tkinter import ttk
from tkinter.messagebox import showinfo
import tkinter as tk

# Create instance
CDU = tk.Tk()

def window(CDU):
CDU.title('ATA: 34-61-14, Liquid Crystal Display Control Display Unit')
CDU.resizable(False,False) # prevent the GUI from being resizable, the same for (0,0)
CDU.overrideredirect(1) # will remove the top badge of window

def donothing():
print("ok, ok I won't")

# print("ok, ok I won't")

def about():
showinfo(title='About', message='Application developed in Python with Tkinter by AQS\nAny problem or suggestion, please contact (941)726-6632')

def start_progressbar():
progress_bar.start()

def stop_progressbar():
progress_bar.stop()

def run_progressbar():
progress_bar["maximum"] = 100
for i in range [101]:
sleep(0.05)
progress_bar["value"] = i #increment progressbar
progress_bar.update() #have to call update() in loop
progress_bar["value"] = 0 # reset / clear progressbar

def test_procedure():
atp = Tk()
atp.geometry('800x480+0+0')
atp.overrideredirect(1) # will remove the top badge of window

def hello():
print ("hello!")

menubar = Menu(atp)
#menubar.config(font=('Arial',11,"bold"))

# create a pulldown menu, and add it to the menu bar
atpmenu = Menu(menubar, tearoff=0)
atpmenu.configure(font=('Arial',11,"bold"))
atpmenu.add_command(label="Step by step", command=hello)
atpmenu.add_command(label="Complete test", command=hello)
atpmenu.add_separator()
atpmenu.add_command(label="Exit", command=atp.destroy)
menubar.add_cascade(label="Test Procedure", menu=atpmenu)

# create more pulldown menus
reportmenu = Menu(menubar, tearoff=0)
reportmenu.configure(font=('Arial',11,"bold"))
reportmenu.add_command(label="View", command=hello)
reportmenu.add_command(label="Save", command=hello)
reportmenu.add_separator()
reportmenu.add_command(label="Open", command=hello)
reportmenu.add_separator()
reportmenu.add_command(label="Send email", command=hello)
menubar.add_cascade(label="Reports", menu=reportmenu)

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

# display the menu
atp.config(menu=menubar)


print("==================================================")
print("Work Order: %s\nUUT_PN: %s\nUUT SN:%s\nTechnician:%s\nDate:%s" % (UUT_wo.get(), UUT_pn.get(), UUT_sn.get(), WO_tech.get(), WO_date.get()))
if radVar.get() == 1: print ("Work Requested: Bench Check")
elif radVar.get() == 2: print ("Work Requested: Repair")
elif radVar.get() == 3: print ("Work Requested: Overhaul")
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")
print("Test Step 1 =========================\n")
print("Test Step 2 =========================\n")
print("Test Step 3 =========================\n")
print("Test Step 4 =========================\n")
print("Test Step 5 =========================\n")

# Button(CDU_test, text=" Return to Main Window ",font = ('Arial', 12, "bold"), command = window(CDU )).grid(row=12, column=4, sticky='e')




def retrieve_report():

WO_retrieve = Entry(CDU, width=30)
WO_retrieve. grid(row=12, column=4, sticky='w')
print("WO Retrieve: %s\n" % (WO_retrieve()))
print("==================================================")
print("Closing session")
print("\n")
print("Bye")
print("\n")
print("==================================================")


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')
UUT_pn = Entry(CDU, width=30)
UUT_wo = Entry(CDU, width=30)
UUT_sn = Entry(CDU, width=30)
WO_date = Entry(CDU, width=11)
WO_tech = Entry(CDU, width=18)
WO_retrieve = Entry(CDU, width=30)
#==========================================================================================
#window(CDU)===========================================================================================

# Add a title, size and disabling resize
CDU.geometry('800x480+0+0')
CDU.title('ATA: 34-61-14, Liquid Crystal Display Control Display Unit')
#CDU.overrideredirect(1) #it removes the top badge
#Label(CDU, text="ATA: 34-61-14, Liquid Crystal Display Control Display Unit").grid(row=0, column=3)

# Adding Labels and Entries widgets =======================================================================
Label(CDU, text="UUT PN:",font = ('Arial', 12,"bold"), fg = 'darkblue').grid(row=1, column=3, sticky='e')
Label(CDU, text="Work Order:",font = ('Arial', 12, "bold"), fg = 'darkblue').grid(row=2, column=3, sticky='e')
Label(CDU, text="UUT SN:",font = ('Arial', 12, "bold"), fg = 'darkblue').grid(row=3, column=3, sticky='e')
Label(CDU, text="Date:",font = ('Arial', 12, "bold"), fg = 'darkblue').grid(row=4, column=3, sticky='e')
Label(CDU, text="Technician:",font = ('Arial', 12, "bold"), fg = 'darkblue').grid(row=5, column=3, sticky='e')

UUT_pn = Entry(CDU, width=30)
UUT_wo = Entry(CDU, width=30)
UUT_sn = Entry(CDU, width=30)
WO_date = Entry(CDU, width=11)
WO_tech = Entry(CDU, width=18)
WO_retrieve = Entry(CDU, width=30)

UUT_pn.grid(row=1, column=4, sticky='e')
UUT_wo.grid(row=2, column=4, sticky='e')
UUT_sn.grid(row=3, column=4, sticky='e')
WO_date.grid(row=4, column=4, sticky='w')
WO_tech.grid(row=5, column=4, sticky='w')

# Radiobuttons ===========================================================================================
# Radiobuttons Callback
def radCall():
radSel=radVar.get()
if radSel == 1: CDU.configure()
elif radSel == 2: CDU.configure()
elif radSel == 3: CDU.configure()

# Create three Radiobuttons using one variable
radVar = IntVar()

Label(CDU, text="Work Requested:",font = ('Arial', 12, "bold"), fg = 'darkblue'). grid(row=7, column=3, sticky='w')
benchtest = Radiobutton(CDU, text="Bench Test", font = ('Arial', 12, "bold"),variable=radVar, value=1, command=radCall)
benchtest.grid(row=7, column=4, columnspan=2, sticky='w')
repair = Radiobutton(CDU, text="Repair", font = ('Arial', 12, "bold"), variable=radVar, value=2, command=radCall)
repair.grid(row=8, column=4, columnspan=2, sticky='w')
overhaul = Radiobutton(CDU, text="Overhaul", font = ('Arial', 12, "bold"), variable=radVar, value=3, command=radCall)
overhaul.grid(row=9, column=4, columnspan=4, sticky='w')

# Canvas =================================================================================================
canvas_width = 291
canvas_height =387
canvas = Canvas(CDU,
width=canvas_width,
height=canvas_height)
canvas.grid(row=1, column=0, rowspan=11, columnspan=2, sticky='n')
img = PhotoImage(file="174101_2.gif")
canvas.create_image(20,20, anchor=NW, image=img)

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

# Functions ===============================================================================================
Button(CDU, text=" Test Procedure ",font = ('Arial', 12, "bold"), command = test_procedure).grid(row=10, column=4, sticky='e', padx=2)
Button(CDU, text=" Retrieve Report ",font = ('Arial', 12, "bold"), command = retrieve_report).grid(row=12, column=1, sticky='e')
Button(CDU, text=" About...",font = ('Arial', 12, "bold"), command = about).grid(row=15, column=1, sticky='e', padx=2)
Button(CDU, text=" Close Session ",font = ('Arial', 12, "bold"), command = ending_session).grid(row=15, column=4, sticky='e', padx=2)

window(CDU)

#==========================================================================================
#Start GUI
CDU.mainloop( )

juliolop
Posts: 20
Joined: Thu Sep 27, 2018 4:33 pm

Re: menubar fonts

Sat Dec 15, 2018 7:52 pm

forget about this post
I was using python in a windows machine
when I run the code in the raspberry works perfectly
:D

Return to “Python”