Reputation: 7313
I am using python 3 and trying to draw a vertical line in tkinter
but I can't find any way to draw without using Canvas
. I googled but found nothing.
Here is my code:
from tkinter import *
master = Tk()
master.geometry('200x346+200+100')
mainloop()
How to solve this problem?
Upvotes: 0
Views: 2789
Reputation: 15355
Here's a right triangle whose non-diagonal lines drawn with Frame
s:
try: # In order to be able to import tkinter for
import tkinter as tk # either in python 2 or in python 3
except ImportError:
import Tkinter as tk
if __name__ == '__main__':
root = tk.Tk()
ratio = 16
vertical_edge_len = 5
horizontal_edge_len = 12
hypotenuse = tk.Canvas(root, highlightthickness=0)
hypotenuse.create_line(0, 0, ratio * horizontal_edge_len,
ratio * vertical_edge_len, fill='green')
vertical = tk.Frame(root, bg='red', height=ratio * vertical_edge_len,
width=1)
horizontal = tk.Frame(root, bg='blue', height=1,
width=ratio * horizontal_edge_len)
vertical.place(x=0, y=0)
horizontal.place(x=0, y=ratio * vertical_edge_len)
hypotenuse.place(x=0, y=0)
root.mainloop()
Upvotes: 0
Reputation: 386362
I am using python 3 and trying to draw a vertical line in tkinter but I can't find any way to draw without using Canvas.
No, there is no general purpose way to draw in tkinter except with the canvas.
If all you need is a vertical line to be used as a separator, you can use a frame that is one pixel wide. Or, use the ttk.Separator
widget.
Upvotes: 3