python - Create a network graph manually - Stack Overflow [Link]
Create a network graph manually
Asked 1 year, 4 months ago Modified 1 year, 4 months ago Viewed 124 times
I am looking to create a program in python that will allow me to draw a graph manually,
that is to say, by placing the points (vertex) and clicking on two vertices in order to connect
-1 them and thus form an edge and above all I am looking to that this graph is not just a
drawing because I have to extract the adjacency and incidence matrices from it and also
apply algorithms on it (DFS, BFS, DJikstra).
I tried and searched everywhere but I can't, I can only create vertices and edges using the
functions of the Networkx library (add_node and add_edge) which do not meet my needs
because with these I can create a graph only by implementations. Here is the interface of
the program I am making, I want that when I click on the "Vertex" option a new window
opens and I can place the vertices and then with the "Edge" option connect two peaks.
enter image description here
Thank you for helping me.
python user-interface graph
Share Improve this question Follow asked Nov 23, 2022 at 15:00
Has891
1
This is way too broad a question. That said, you're not going to find something that does the
entirety of what you're describing for you. What you need to do is learn to use a GUI library that will
let you take mouse input and translate it to the screen, and then write your own logic to connect
those mouse inputs to a graph library such as you describe. – Edward Peters Nov 23, 2022 at 15:11
They're asking for a python library, right, not just a standalone tool? Am I missing something?
– Edward Peters Nov 23, 2022 at 15:50
1 Answer Sorted by: Highest score (default)
1 de 2 08/04/2024, 22:33
python - Create a network graph manually - Stack Overflow [Link]
If you have a decent GUI framework, then this sort of thing is easily accomplished.
As a first step, you need to implement the following
1
Add node
move mouse cursor to location
click right mouse button
select "Add Node" menu item from pop-up
node will be displayed at mouse location as a black circle
Select node
move mouse cursor over node
click left mouse button
selected node will be drawn in red
Add link
select first node
move mouse cursor over second node
click right mouse button
select "link" menu item from pop-up
link will be drawn between nodes
Move node
move mouse cursor over node
press and hold left mouse button
drag mouse while holing down left button.
( the node and connected links will follow the mouse curor )
release button at reuired new location
As an example of how this can be done, you may find it helpful to take a look at an
implementation using C++ at [Link] This uses the
WINDEX gui framework - most gui frameworks offer the same methods, so it should be a
straightforward task to port this line by line to python.
Share Improve this answer edited Nov 24, 2022 at 15:50 answered Nov 23, 2022 at 22:37
Follow ravenspoint
19.7k 7 61 105
2 de 2 08/04/2024, 22:33