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

  • SEARCH
  • Home
  • 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 9324781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:41:04+00:00 2026-06-19T04:41:04+00:00

So I’m learning python and the book that is teaching me gives me two

  • 0

So I’m learning python and the book that is teaching me gives me two ways to create a label using tkinker:

self.canvas.create_text(30,10,text="Welcome",tags="text")

&

self.lbl = Label(frame1, text = "Welcome")

In the former example, moving it is easy:

self.canvas.move("text", 1, 0)

In the latter example, changing it’s background color is easy:

self.lbl["bg"] = "red"

However I do not know how to both move it AND change it’s background color in either example, at least not how to move it incrementally. I can do this:

 self.lbl.place(x=2)

But unless I can get the x coordinate ahead of time, I can only move it once. I could set it ahead of time, but I’d like to avoid that option if possible.

  • 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-19T04:41:05+00:00Added an answer on June 19, 2026 at 4:41 am

    There are ways to do both.

    Firstly, Canvas text does not have a background, but you can create your own with a rectangle.

    text = self.canvas.create_text(30, 10, text="Welcome", tags="text")
    # The canvas.bbox method returns the corner coordinates of the provided item id.
    rect = self.canvas.create_rectangle(self.canvas.bbox(text), fill='red')
    # Then you need to reposition the rectangle so that it is behind the text.
    self.canvas.lower(rect, text)
    

    From there you just move them the same way as you mentioned in your question. Adding a group tag to both the text and rectangle would save you from having to move both items separately.

    Secondly, you can get the current x, y coordinates of a widget with the .winfo_x() and .winfo_y() methods. So moving the Label becomes a simple matter of addition/subtraction:

    self.lbl.place(x=self.lbl.winfo_x()+2)
    

    I do not know of a method that moves a widget in increments as the move method does for the canvas.

    As for which is best, I can’t think of much between them. I suppose using a Canvas would mean you couldn’t overlap any other widgets that may be in the window, since the text would just scroll out of view, and if you start using the ttk version of Label then styling isn’t quite as straight forward, although it’s not difficult.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to create an if statement in PHP that prevents a single post
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.