Python Tkinter - How to move a textbox by pixels - python

What the title says.
I'm having a problem moving the textbox from a side to side.
The code's long and it's about 200+ lines so I wont post it here.
Anybody has an idea?

You have various options for this, depending on what you mean by "text box," and whether you want to move it "by pixels" or "from a side to [another] side."
If you just want to display text, you can use a Label widget. If you want a text box where the user can enter text, try an Entry widget. If you want to move your widget from one area of the screen to another, you can use the grid geometry manager and simply use grid_forget to "unplace" your widget then grid (with different options than you originally used, of course) to put it somewhere else.
If you just have text and you'd like to move it pixel by pixel, you could create a Canvas and then use that widget's create_text method to create some text in a specific place on the Canvas. You can the use the Canvas widget's itemconfig method to move the text to a new location.
If you need something more complex than text, like an Entry widget, and you want to move it pixel by pixel, do the same as above but use the create_window method instead.
See Canvas, grid, Label, Entry, and these SO questions about create_window.

Related

How to make Entry box in Tkinter transparent?

I want to make my Entry box without any color and only shows the cursor so it will blend with the canvas image. Here is what I want to make objective design and here is what I am able to make current design.
I did try the root.wm_attributes("-transparentcolor", "yellow") but it will also make the frame invisible. How do I make the entry box transparent without affecting the background. My code is based on the link below.
https://github.com/ajinkyapadwad/Tkinter-HosoKeys

Draw line on text widget in Tkinter [duplicate]

I was wondering whether it is possible to use some of the tkinter canvas drawing methods on a text widget. Ideally I would have the text widget placed onto the canvas so that I can draw onto the canvas and make it look like it shows up on the text widget.
No, it is not possible to draw over or into a tkinter Text widget. You can, however, add text to a canvas with the create_text method and draw over that.

Adding a vertical bar or other marker to tkinter Text widgets at a particular column

My intention is to add a vertical bar to IDLE to indicate preferred line length at column 80.
I have tried to find a configuration option for the Text tkinter widget that would allow this but have found nothing.
I was hoping it would be a simple configuration option so I could just add a another item the text_options dictionary within EditorWindow.py found within Python\Lib\idlelib.
I am not sure how styles/themes work but do they have the capability to change the background colour of only 1 column in a Text widget?
Outline of possible solution:
Create a 1-pixel wide Frame, with a contrasting background color, as a child of the Text.
Use .place() to position the Frame at an appropriate horizontal coordinate.
Possible issues:
I don't see any easy way to get the coordinate for a particular column. Text.bbox("1.80") looks promising, but doesn't work unless there actually are 80 characters in the line already. You may have to insert a dummy 80-character line at first, call update_idletasks to get the Text to calculate positions, call bbox to get the coordinates, then delete the dummy text. Repeat whenever the display font is changed.
The line would necessarily appear on top of any text or selection region, which isn't quite the visual appearance I'd expect for a feature like this.

Tkinter title with line around area

So in tkinter I'm making a program, I want to know can you make a title box thing like the one in this image with the title "Booking Details"?
Sounds like you want a Label Frame.
The LabelFrame widget is a variant of the Tkinter Frame widget. By default, it draws a border around its child widgets, and it can also display a title.

Resizing frames in Tkinter

I have been making a small program with the Tkinter module in python, and I was wondering whether it was possible or not to resize a frame in my program with the mouse. As in, the user can drag the frame border and it will resize itself.
Your use of terminology makes the question unclear. Windows which may be resized by the user are called Toplevel windows. These are what appear as rectangular windows on the display, with a frame around them, typically a title bar, and edges or corners that can be grabbed and resized.
The term Frame refers to a container widget that must be inside a Toplevel or one of its descendents. A Frame has the ability to be resized but you have to write the code to let you interactively resize them. For example, you could place a little grip widget in one or more corners, and writing bindings to the press, motion and release of a mouse button.
Depending on the effect you are looking for, you might want a PanedWindow which is a container that includes a sash that lets you adjust the proportion of space between two other widgets.

Categories