How do i change the colour of a button border tkinter

2024/11/17 7:24:20

How do i change the colour of a border in tkinter

I have looked at other solutions which recommended using highlightcolor and highlightbackground, however these did not work.

excercises_button = Button(canvas, width=327, height=150, image=dumbell_img,borderwidth=4, relief="ridge", bg = "gray55", command = Excercises)
canvas_excercises_button = canvas.create_window(168, 724, window=excercises_button)

I would like the border of this button to be orange.

This is what it currently looks like: https://i.sstatic.net/3QX8X.png

Answer

Here is an example of how one can have a kind of border created by using a frame and a button.

import tkinter as tkroot = tk.Tk()frame = tk.Frame(root, highlightbackground="orange", highlightcolor="orange", highlightthickness=4, bd=0)
frame.grid(row=0, column=0)
# adding weights so the button is center on the frame.
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)btn = tk.Button(frame,text="test", borderwidth=4, relief="ridge", bg = "gray55").grid(row=0, column=0)
root.mainloop()

Results:

enter image description here

https://en.xdnf.cn/q/118832.html

Related Q&A

module object has no attribute Gridspec despite calling help(gridspec) revealing the Gridspec class

If I run the python console and doimport matplotlib matplotlib.__version__ import matplotlib.gridspec as gsI see that the matplotlib version is 1.2.1.If I do help(gs) I see the Gridspec class.However t…

Python division doesnt work as expected for large numbers [duplicate]

This question already has answers here:What class to use for money representation?(6 answers)Closed 9 months ago.I have three variables a, b and c. I want to make sure that after doing this: c -= a*bc…

working out an average of the values in a dictionary

My dictionary as of now is like this:class_1 = {Bob:[9,5,4,3,3,4], John:[5,5,7,3,6], Andy:[7,5,6,4,5], Harris:[3,4,2,3,2,3,2]}What i am trying to make it look like is this:class_1_average ={Bob:[averag…

getting an error when trying to import a list into a mysql table

whenever i try to add a list into the mysql table I get an error : ProgrammingError: Not all parameters were used in the SQL statementive tried to look online but all i could found is that i need to us…

Getting a view does not return a valid response error message on my flask chatbot [duplicate]

This question already has answers here:Flask view return error "View function did not return a response"(3 answers)Closed 3 years ago.Trying to create a whatsapp bot on Twilio that limits the…

Django how to add data to Object from queryset

I would like show list of clients and show tags assigned to them but I have problem because I have my tags in other table and I dont know how to connect data together. Clients can have couple of tags o…

before_action ... only: how to do this in python flask? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 5 years ago.Improve…

Destroy function not destroying a frame efficiently after the first iteration in Tkinter Python

I have built a code that saves the calculated data at every iteration in a for loop and the results are stored in 3 different csv files. These saved results are read in another python code that display…

Access columns and rows of numpy.ndarray

I currently struggling with extracting certain columns and rows from a matrix stored as a numpy.ndarray. I have a list in which Ive appended these numpy.ndarrays. This list is stored in a variable name…

How to access instance object in list and display there data? in python

class Bank:def __init__(self, name, balance=0):self.name = nameself.balance = balance# def Display_details(self):# print( self.name),# print(self.balance),#### def Withdraw(self, a):# self.…