0

I'm writing a program with pyinstaller and tkinter. At the startup, I want to show a scrolling textbox with information. The textbox itself appears on a Toplevel, and there is a close button:

  from tkinter import Tk,BOTTOM,Toplevel,INSERT,Button
  import tkinter.scrolledtext as st

  win = Tk()
  win.title("Main Window")

  info_window = Toplevel()
  info_window.wm_title('Licensing')
  info_window.attributes('-topmost', 'true')

  text_area = st.ScrolledText(info_window,
                        width = 50, 
                        height = 5, 
                        font = ("Times New Roman",
                                15))

  text_area.pack()

  text_area.insert(INSERT,
  """\
  This software is licensed under ..... 
  It is distributed as is and may used provided...
  You pay me handsomely
  You are my friend

  References:
  1. Doe, John, A Meaningless Research Result, Journal of Meaningless Research, 14 
  (1), 2022, 235-236.
  2. Smith, Jill, A Substantial Research Result, Journal of Substantial Research, 34 
  (6), 2022, 112-118.
  """)

  text_area.configure(state ='disabled')

  def close_window():
      info_window.destroy()

  close_button=Button(info_window, 
  text="Close",fg='black',bg='white',borderwidth=0,command=close_window)
  close_button.pack(side=BOTTOM,expand=True)

  win.mainloop()

This works, but I'd like to do the following:

  1. Center the "References" title
  2. Put journal titles in italics
  3. Put journal volumes in boldface

and....

  1. Make the Toplevel() static and not resizeable.
fishbacp
  • 1,123
  • 3
  • 14
  • 29
  • Pretty much everything you want to do is covered by existing documentation. It's not clear why you need our help. – Bryan Oakley Apr 20 '22 at 16:37
  • Perhaps I'm missing something, but I'm having a hard time finding the specifics. After posting this, I did discover how to keep the Toplevel static, thanks to your helpful response to a question posted at https://stackoverflow.com/questions/37446710/how-to-make-a-tkinter-window-not-resizable On the other hand, while I see how to adjust properties of text_area as a whole, I can't locate info for adjusting specific content, such as the journal titles, volume numbers as described in my question. – fishbacp Apr 20 '22 at 16:45
  • 1
    Read through the documentation for the `Text` widget - it mentions tags that can be applied to ranges of text, and that can be configured to have unique properties. – Bryan Oakley Apr 20 '22 at 16:47
  • You might find this helpful: https://stackoverflow.com/q/3732605/7432 – Bryan Oakley Apr 20 '22 at 16:52
  • Thanks. I see now how tags can be used. – fishbacp Apr 20 '22 at 17:40

1 Answers1

1

I added the code for how to keep the window from resizing. As for the other questions, as mentioned in the comments there is documentation for your options on this. It looks like you are setting your font style in the ScrolledText widget, therefore all the text inserted into that widget are going to have those font attributes. I think you would need to approach it with a different tactic. Independently configure the texts that need to be different and then recombine the information to display it to the user in the format you want, perhaps utilizing different widgets.

from tkinter import Tk,BOTTOM,Toplevel,INSERT,Button
import tkinter.scrolledtext as st

win = Tk()
win.title("Main Window")

info_window = Toplevel()
info_window.wm_title('Licensing')
info_window.attributes('-topmost', 'true')
info_window.geometry("600x300") #set window size in pixels
info_window.resizable(False, False)# prevent window from being resizable

text_area = st.ScrolledText(info_window,
                    width = 50, 
                    height = 5, 
                    font = ("Times New Roman",
                            15))

text_area.pack()

text_area.insert(INSERT,
"""\
This software is licensed under ..... 
It is distributed as is and may used provided...
You pay me handsomely
You are my friend

References:
1. Doe, John, A Meaningless Research Result, Journal of Meaningless Research, 14 
(1), 2022, 235-236.
2. Smith, Jill, A Substantial Research Result, Journal of Substantial Research, 34 
(6), 2022, 112-118.
""")

text_area.configure(state ='disabled')

def close_window():
  info_window.destroy()

close_button=Button(info_window, 
text="Close",fg='black',bg='white',borderwidth=0,command=close_window)
close_button.pack(side=BOTTOM,expand=True)

win.mainloop()
Rory
  • 661
  • 1
  • 6
  • 15