I am trying:
from ipywidgets import Text, Layout
Text('test', layout=Layout(height='15px'))
but, it doesn't shrink the height of the Text widget frame. Instead, it just shows the frame cropped. See here:
How to properly get a Text widget with a specified frame height?
Related
How to pad the location for the image on the label?
I am working on project in which the image is basically the size of the label and some text that I want to show isn't visible...when I remove the image, the label text is shown. I have to pad the location for the image on the label.
The label automatically resizes to account for the size of the image, so what you can do is, use the compound option to move the image to whichever position you prefer.
From a doc:
If you would like the Label widget to display both text and a graphic (either a bitmap or an image), the compound option specifies the relative orientation of the graphic relative to the text. Values may be any of tk.LEFT, tk.RIGHT, tk.CENTER, tk.BOTTOM, or tk.TOP. For example, if you specify compound=BOTTOM, the graphic will be displayed below the text.
So:
Label(root,text='Image 1',image=img,compound='top').pack()
table is created in Qt Designer with settings:
In the main.py i just resized the columns:
self.table1.setColumnWidth(0, 150)
self.table1.setColumnWidth(1, 700)
If i run main.py i get:
My problem is: If i resize the window. I would like to keep the width of the Status column the same and only increase the width of the Description column. Has someone an idea how to do this?
You must set the setSectionResizeMode(index, mode) of the specific section of the horizontal header.
self.table1.horizontalHeader().setSectionResizeMode(
1, QtWidgets.QHeaderView.Stretch)
I am creating an app using Python Tkinter in which I give the users an option to insert an image into a text widget. I know that when you insert an image, and you don't specify the name attribute, tkinter automatically generates one. There is also a way to get a tuple of all the names in the text widget using the text.image_names() method. All the methods I have looked at, that relate to text widget images only take the image's index as an attribute. However, I don't know the image's index.
It would be nice if anyone could tell me if there is a method where I give the function the image's name is an attribute, and get the index in return.
You can use Text.index() on the image name to get the image index in "line.column" format.
Below is an example:
import tkinter as tk
root = tk.Tk()
text = tk.Text(root, width=80, height=20)
text.pack()
text.insert('end', 'This is line 1\n')
text.insert('end', 'Embed an image ')
img = tk.PhotoImage(file='sample.png')
text.image_create('end', image=img, name='img1')
text.insert('end', ' in a line')
print('Image with name "img1" is at index', text.index('img1'))
root.mainloop()
You will get Image with name "img1" is at index 2.15 in the console.
I am using tkinter.filedialog.askopenfilename in Python to select a file. How do I change the font size for the file list displayed? I have found answers on StackOverflow on how to change the font of some items on the display (for example here), but do not know the name of the ttk widget that is used for the file list.
I'm plotting something using matplotlib in python and want to show the plot in GTK. I'm following this tutorial. The problem is I want to embedded the plot in textview. So I want to convert it to pixbuf and append it to textview.
It's not a problem if I save it first and load it later as a pixbuf and append it to textview. But, I want to do it directly without saving any file.
Below is a sample code from link
self.figure = Figure(figsize=(100, 100), dpi=75)
self.axis = self.figure.add_subplot(111)
self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
self.canvas.show()
self.graphview = builder.get_object("plot")
self.graphview.pack_start(self.canvas, True, True)
Can I convert the plot in self.canvas into pixbuf so that I can embedded it to textview?
I have written a class, which uses GdkPixbuf as the backend of metaploitlib, full source code and demo can be found here: metaploitlib_backend_pixbuf
If we get a pixbuf, then we can easily insert it to a textview.
Below is the screenshot which uses GtkImage to display that pixbuf: