Sep-30-2021, 03:21 AM
[attachment=1289]
Hello all,
I am trying to change the font of within the tkinter's frame title. I've come across a few methods on the internet but none of the methods work as expected. The most common answer was to add 2 lines of code:
[attachment=1290]
Below is the code for the entire window. If i uncomment lines 36 and 37 I get an error and nothing happens. I am not sure what is happening, if anyone can explain a bit more what those 2 lines of code are doing that would be much appreciated. Thanks in advance!
error:
Hello all,
I am trying to change the font of within the tkinter's frame title. I've come across a few methods on the internet but none of the methods work as expected. The most common answer was to add 2 lines of code:
s = ttk.Style() s.configure('TNotebook.Tab', font=('URW Gothic L','11','bold') )However, this code doesn't work. It resets all my other fonts, it also gives me an error when I try to use an image. Also, a second tkinter window opens, which i've never seen before.
[attachment=1290]
Below is the code for the entire window. If i uncomment lines 36 and 37 I get an error and nothing happens. I am not sure what is happening, if anyone can explain a bit more what those 2 lines of code are doing that would be much appreciated. Thanks in advance!
error:
Traceback (most recent call last): File "C:\Users\Sami Hawasli\Documents\Python\LMX2820_GUI_Tabs.py", line 36, in <module> logo = Label(win, image = img) File "C:\Program Files (x86)\Thonny\lib\tkinter\__init__.py", line 2766, in __init__ Widget.__init__(self, master, 'label', cnf, kw) File "C:\Program Files (x86)\Thonny\lib\tkinter\__init__.py", line 2299, in __init__ (widgetName, self._w) + extra + self._options(cnf)) _tkinter.TclError: image "pyimage1" doesn't exist
from tkinter import * from tkinter import ttk import tkinter.font from PIL import ImageTk, Image s = ttk.Style() s.configure('TNotebook.Tab', font=('URW Gothic L','11','bold') ) def close(): win.destroy() #Initialize Output A and 2 on/off state RFA = 1 RFB = 0 ErrorMessage = "Please Initialize" ### Gui definitions ### win = Tk() win.resizable(False, False) #win.geometry("1000x1000") win.title("Part Number: DGRF2820 Rev1 Software ver 1.0") titleFont = tkinter.font.Font(family="Garamond", size = 18, weight = "bold") #Garamond titleFontSmall = tkinter.font.Font(family="Garamond", size = 14, weight = "bold") bodyFont = tkinter.font.Font(family="Garamond", size = 14) errorFont = tkinter.font.Font(family="Garamond", size = 12) win.iconbitmap("DGRF_Icon.ico") ### Header Row ### TitleLabel = Label(win, text = ('DGRF Frequency Synthesizer 45 MHz - 22 GHz'),font=titleFont) TitleLabel.grid(row=0,column=1,columnspan=8) #InitButton = Button(win,text='Initialize',font=bodyFont,command= lambda: LMX2820Init(RefDoublerVar.get(),int(RefPreDiv.get()),int(RefMultiVar.get()),int(RefPostDiv.get())) , bg = "bisque2") #,bg='grey') #InitButton.grid(row=0, column=8) ### Footer Row ### img = ImageTk.PhotoImage(Image.open("DGRF_Logo_Smaller.png")) #logo = Label(win, image = img) #logo.grid(row=100,column=1) ErrorLabel = Label(win, text = (' Error messages:'),font=titleFontSmall) ErrorLabel.grid(row=100,column=2) ErrorMessageLabel = Label(win, text = ErrorMessage,font=errorFont) ErrorMessageLabel.grid(row=100,column=3, columnspan=4) exitbutton = Button(win,text='EXIT',font=bodyFont,command=close,bg='red',height=1,width=10) exitbutton.grid(row=100, column=8) RFnotebook = ttk.Notebook(win) RFnotebook.grid(row = 1, column = 1, columnspan=8) RFframe1 = Frame(RFnotebook,width = 1500, height = 500) #bg = "blue") RFframe2 = Frame(RFnotebook,width = 1500, height = 500) #bg = "red") RFnotebook.add(RFframe1, text="Reference Chain") RFnotebook.add(RFframe2, text="CW output") win.mainloop()