0

Good day! I would like to ask a question about Tkinter Frame or Window. Does it support partial border like I want to have a border for only on the bottom and left side and opacity of let's say around 65%? Thank you!

Daniel Bellmas
  • 589
  • 5
  • 17
Nymph
  • 41
  • 4
  • 1
    Can you show what you have tried? –  Jun 13 '21 at 16:01
  • I don't think tkinter supports that but you can just create another frame that is 1 pixel thick with no border and set it's background to whatever you need. – TheLizzard Jun 13 '21 at 16:29
  • @Sujay There isn't really anything to try. OP either knows how to get the feature or they don't. To get a minimal working example just use: `import tkinter as tk; root = tk.Tk()`. – TheLizzard Jun 13 '21 at 16:31

2 Answers2

0

Try something like this:

import tkinter as tk

BORDER_THICKNESS = 3

root = tk.Tk()

canvas = tk.Canvas(root)
canvas.pack(fill="both", expand=True)

bottom_border = tk.Frame(root, height=BORDER_THICKNESS, bg="red", highlightthickness=0, bd=0)
bottom_border.pack(fill="x")

root.mainloop()

The code produces a window like this:

Result

The grey line bellow the red one is tk.Tk()'s border.

I created a 3 pixel thick tkinter.Frame with a red background and made sure that it doesn't have a border. It will be trivial to add another red line on the left.

About the opacity: you can just change the colour of the frame or try something like this.

TheLizzard
  • 7,248
  • 2
  • 11
  • 31
  • Thank you @TheLizzard! I have something like this and I want to remove the top border and right border. and also I want to make my border to be round and the border opacity to have 65%. will it have a capability in tkinter or what option can I have? I dont know how to insert a picture here as I am new to this. Thank you from tkinter import * root = Tk() frame1 = Frame(root, highlightbackground="#701d47", highlightthickness=4,width=600, height=100, bd= 0, bg="#ffcc70") frame1.pack() root.mainloop() – Nymph Jun 13 '21 at 17:34
0

No, tkinter widgets don't support partial borders and doesn't support opacity. However, you can create your own style or draw your own borders fairly easily.

For example, to create an entry with a border only along the bottom, you can create an entry with no border and then use place to create a border along one edge.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

entry = tk.Entry(root, borderwidth=0)
border = ttk.Separator(entry, orient="horizontal")
border.place(x=0, rely=1.0, height=2, relwidth=1.0)

entry.pack(side="top", padx=20, pady=20)

root.mainloop()

screenshot

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Thank you @Bryan! Would you recommend me with another GUI widget that I can use that can able to cater to this? what GUI are you using? – Nymph Jun 13 '21 at 17:49
  • @Nymph: I don't understand your question. I'm using tkinter. I don't know what you mean by "another GUI widget". You can use this technique with any widget. – Bryan Oakley Jun 13 '21 at 17:51
  • I think I have found https://stackoverflow.com/questions/51425633/tkinter-how-to-make-a-rounded-corner-text-widget.. but I think this is too advance for me.. I want to thank you for answering my inquiry :) – Nymph Jun 13 '21 at 18:14