0

Hi !

I've been looking all over StackExchange and some other forums for an answer to my question but I couldn't find anything relevant, so here I am, posting my question.

What I'm trying to do is to draw lines that are on the same layer as other Tkinter widgets. I'm currently coding an interface where certain widgets need to visually connect to each other (NodeBox style or Quartz Composer style).
Shows the connectors (noodles) present in Quartz Composer. (I'm not necessarily looking for curved lines, straight is more than enough.)

The problem is that it is too complicated to use the canvas widget (I will be using a lot of widgets so embedding all of them into the canvas is not really an option I think). I'm looking for something similar to the separator widget but allowing for diagonal lines and defined by coordinates. I'm thinking of creating a custom widget that does this but I'm not sure where to start. An other solution may be to have a transparent canvas right over the non-canvas widgets but that would complicate the mouse click events a lot. I don't know what option would be the best.

Any thoughts on how I could accomplish drawing lines out of canvas widget? (Or on how I can create a custom widget that does this?)

Pharoah Jardin
  • 134
  • 2
  • 9
  • What does "too complicated" mean? How is it complicated? – Bryan Oakley Aug 11 '16 at 16:12
  • @BryanOakley The thing is I want to make these draggable "components" that will contain text, "inputs" and "outputs" and to place these inside I need `pack()` or `grid()`. I can't use the `pack()` or `grid()` geometry managers so that means I would have to code similar managers myself. I think that would be complicated... It seems much simpler to implement a sort of line widget that I can `place()`. – Pharoah Jardin Aug 11 '16 at 19:31
  • if you want to drag things around, the canvas gives you complete control over that. Laying things out in a grid is just a little math. And to be honest, you _can_ use `pack` and `grid` inside a canvas, but you'll lose the ability to drag things around, and you'll lose the ability to scroll. The scrolling can be solved, but needing to drag and drop with `pack` or `grid` will be pretty difficult. – Bryan Oakley Aug 11 '16 at 19:38
  • @BryanOakley Really ? I didn't think that those methods were available in a canvas. What if I make a draggable canvas-window and use `grid` inside it ? Is that possible ? Btw, thanks a lot for your helpful responses! – Pharoah Jardin Aug 11 '16 at 19:56
  • You can use grid on widgets inside the canvas, but then they won't be draggable. Being draggable (to me) implies you can drag it anywhere. `grid` is designed to decide place a widget in a row and column. If you want to drag it, why use grid? – Bryan Oakley Aug 11 '16 at 20:34
  • @BryanOakley Your right. I'll just make a draggable frame class that goes over the canvas. And the connectors (lines) will have to be under the frames, but it's ok I don't mind. Sorry if I'm not very clear ! But basically my problem is solved ;) Thanks for your help ! – Pharoah Jardin Aug 11 '16 at 22:13

1 Answers1

0

Your only reasonable choice for drawing lines is the canvas. Without the canvas you can simulate horizontal or vertical lines using a separator and place, but you can't do diagonal lines.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685