Is it possible to orient a tk.Button
or ttk.Button
vertically? Smething like orienting a tk.Scrollbar
in a way self.scrlbr = tk.Scrollbar(master, orient = vertical)
?
Have tried tk.Button(*args).pack(fill = tk.Y)
, but it does not provide desired effect - button still gets horizontally oriented.
Found nothing in man pages, but maybe there is some not-staightforward way?
The button widget does not provide this option but you can emulate the button widget to get the effect if required. One way, as mentioned is to use an image containing the rotated text. Depending on your theme you may also create a button using a canvas
which allows you to rotate text drawn on itself using the angle
option. This would look odd on Windows themes but could look normal where the widgets being used are Tk (and not ttk widgets) or with ttk provided the theme is one that uses Tk drawn elements (the default on unix).
A crude demo of how it would look:
import tkinter as tk
import tkinter.font as tkfont
main = tk.Tk()
font = tkfont.nametofont("TkDefaultFont")
label = "Click Me"
height = font.measure(label) + 4
width = font.metrics()['linespace'] + 4
canvas = tk.Canvas(main, height=height, width=width, background="SystemButtonFace", borderwidth=2, relief="raised")
canvas.create_text((4, 4), angle="90", anchor="ne", text=label, fill="SystemButtonText", font=font)
canvas.bind("<ButtonPress-1>", lambda ev: ev.widget.configure(relief="sunken"))
canvas.bind("<ButtonRelease-1>", lambda ev: ev.widget.configure(relief="raised"))
canvas.place(x=5, y=height + 10)
main.mainloop()
I found an answer that is a bit easier. for example lets say you have 4 horizontal ttk.buttons, and you wish to place a vertical ttk.button next to them lets call our new button config. Using the grid method for the buttons, the first vertical button is at col=0, row=0 second at col=0, row=1 etc
Create a button with with=4 text=C\no\nn\nf\ni\ng\n, grid at col=1, row=0, rowspan=4,
There you have it. Simple and easy using standard tkinter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With