Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7724685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:45:04+00:00 2026-06-01T04:45:04+00:00

I have recently been using WxPython to create a GUI Network simulator like Cisco

  • 0

I have recently been using WxPython to create a GUI Network simulator like Cisco packet tracer but if I am honest it has been extremely difficult trying to find examples of what I need etc etc. Iv resorted back to the old faithful Tk.

My program thus far has a menu bar which consists of a File > Exit. It also has an Exit button at the bottom Right hand side of the application. As well as this it has a canvas of a set size and a variety of buttons which when clicked produce a small image of the hardware on the canvas. This was done using PIL

What I need next is to be able to drag these images around the canvas and this is proving a little difficult. I have looked at the following example of how it has been broken down and I kind of understand how you need an on click definition, motion (going from a to b) and on release definition, but how do I apply it to my code that I already have?

Here is the link to what I referenced above:
http://www.python-forum.org/pythonforum/viewtopic.php?f=4&p=75789

Finally Here is the code I have already. I can appreciate that the layout and structure of my code isn’t great as I am fairly new to programming but any guidance / examples / visual representations would be amazing.

  from Tkinter import*
from PIL import Image, ImageTk
class AllTkinterWidgets:
    def __init__(self, master):
        frame= Frame(master, width=900, height=600)
        frame.pack()

        iframe5 = Frame (frame, bd=2, relief=RAISED)
        iframe5.pack(expand=1, fill=X, pady=10, padx=5)

        c = Canvas(iframe5, bg='white', width=600, height=500)
        c.pack()

    # definitions to print hardware images to the canvas
    # -----------------------------------------------------------------------
        def show_imageRouter():
            c.create_image(30,30, image=image1)

        def show_imageSwitch():
            c.create_image(30,60, image=image2)

        def show_imageServer():
            c.create_image(30,100, image=image3)

        def show_imageIpPhone():
            c.create_image(30,140, image=image4)

        def show_imageWirelessRouter():
            c.create_image(30,180, image=image5)

        def show_imageHost():
            c.create_image(30, 220, image=image6)

    # Network hardware buttons created
    # ----------------------------------------------------
        self.button = Button(frame, text = "Router", height= 1, width= 8, padx=2, pady=2,command=show_imageRouter)
        self.button.pack(side = LEFT)

        self.button = Button(frame, text = "Switch",height= 1, width= 8, padx=2, pady=2, command=show_imageSwitch)
        self.button.pack(side = LEFT)

        self.button = Button(frame, text = "Server",height= 1, width= 8, padx=2, pady=2, command=show_imageServer)
        self.button.pack(side = LEFT)

        self.button = Button(frame, text = "IP Phone",height= 1, width= 8, padx=2, pady=2, command=show_imageIpPhone)
        self.button.pack(side = LEFT)

        self.button = Button(frame, text = "Wireless Router",height= 1, width= 12, padx=2, pady=2, command=show_imageWirelessRouter)
        self.button.pack(side = LEFT)

        self.button = Button(frame, text = "Host",height= 1, width= 8, padx=2, pady=2, command=show_imageHost)
        self.button.pack(side = LEFT)

        self.button = Button(frame, text = "Cabling",height= 1, width= 8, padx=2, pady=2)
        self.button.pack(side = LEFT)

        self.button = Button(frame, text = "Square",height= 1, width= 8, padx=2, pady=2)
        self.button.pack(side = LEFT)

    # Create the image objects for the hardware Images
    # ----------------------------------------------------------------------
        imageFile = "router.png"
        image1 = ImageTk.PhotoImage(Image.open(imageFile))

        imageFile = "switch.png"
        image2 = ImageTk.PhotoImage(Image.open(imageFile))

        imageFile = "Server.png"
        image3 = ImageTk.PhotoImage(Image.open(imageFile))

        imageFile = "ipPhone.png"
        image4 = ImageTk.PhotoImage(Image.open(imageFile))

        imageFile = "WirelessRouter.png"
        image5 = ImageTk.PhotoImage(Image.open(imageFile))

        imageFile = "Host.png"
        image6 = ImageTk.PhotoImage(Image.open(imageFile))

root = Tk()
all = AllTkinterWidgets(root)

def Exit():
    print "Exit"

# Create an Exit Button
toolbar = Frame(root)
b = Button(toolbar, text="Exit", width=6, height=3, command=Exit)
b.pack(side=RIGHT, padx=2, pady=2)
toolbar.pack(side=BOTTOM, fill=X)

# Press Esc to quit
root.bind("<Escape>", exit)

# Creation of a menu File > Exit
menu = Menu(root)
root.config(menu=menu)

filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Exit", command=Exit)

root.mainloop()

Sorry if the indentation is a bit strange. I’ve adjusted it to make it block together here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:45:05+00:00Added an answer on June 1, 2026 at 4:45 am

    This answer to the question “board drawing code to move an oval” shows how to drag an object on a canvas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently been using sitecake, I like the drag and drop interface of
I have been using Clojure alot recently but I still don't understand what functionality
I have been using Rstudio a great deal these days but recently noticed that
I have been using NotePAD++ for editing Python scripts. I recently downloaded the PyDEV
I have only recently started using CakePHP and have been unable to get validation
I don't have much experience with Serial I/O, but have recently been tasked with
I have recently been using junit in eclipse and I am still learning. I
I have recently been getting my feet wet in MongoDB using Mongoid w/ Rails
I am using Beautiful Soup 3.2 on python 2.7.1 here. I have recently been
I have very recently been learning python. I have been using pyscripter as is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.