I need to create a Checkbutton with indicatoron = FALSE (meaning no indicator should be drawn) and relief = FLAT (meaning border should be normal and not standout from its environment. I can't seem to get both working at the same time. Is there any way around this? Example code below:
def create_buttons(self):
self.zerozeroButton = Checkbutton(self.frame_buttons, indicatoron = FALSE, text = "00", command = self.zerozero, relief = FLAT)
Set the borderwidth to zero. Though, if you have no border and no indicator, I'm not sure how the user will know what the state of the widget is.
Or, perhaps you want the relief when selected but flat when deselected. If that is the case, leave the borderwidth and relief alone, but set offrelief to FLAT.
Related
I am trying to add buttons with custom bg or image so like 3d color. But it gives a white unclickable button as result. I tried many other ways but failed, the code i gave below its a code which lets us to select the weight and height we want for the button that's why i choosed it otherwise if other things like the .zoom or making a function to make the image fit the button were working i would be using them, they are all not working and i have no idea, i know i must be doing something wrong but wellas you see i am new in python, i learned everything myself so really i am 0 x). I Resized the image aswell, it has the same weight height with the button:
root.geometry(geo)
image = ImageTk.PhotoImage(file='background.png')
label = Label(root, image=image)
label.pack(fill='both', expand=True)
label.image = image
myWidth = 150
myHeight = 82
img4=Image.open('button.png')
image4=img4.resize((myWidth,myHeight))
useImg4=ImageTk.PhotoImage(image4)
quitBtn = Button(label, image=useImg4,command=lambda: root.destroy())
quitBtn.pack()
do you know why its not working?
The result:
Is there any way to remove the border around a checkbutton? I have tried relief = "flat", offrelief = "flat", borderwidth = 0 and highlightthickness = 0 and none of these have made any difference. I also found This question, but the first answer doesn't work, and the second involves recreating the widget, but I wish to use the Checkbutton widget. The reason I need to remove the border is that I'm wrapping the button in a frame to change it's border, and If I can't remove the default border, it isn't possible.
This is the border I mean:
I got a problem with changing the height of the Treeview.heading. I have found some answers about the dimensions of Treeview.column, but when I access Treeview.heading in the documentation, there is not a single word about changing the height of the heading dynamically when the text doesn't fit (and wrapping it) or even just hard-coding height of the heading in pixels.
I don't have to split the text to two rows, but when I just keep it that long the whole table (as it has many entries) takes up the whole screen. I want to keep it smaller, therefore I need to split longer entries.
Here is how it looks like:
I can't find any documentation to verify this but it looks like the height of the heading is determined by the heading in the first column.
Reproducing the problem
col_list = ('Name', 'Three\nLine\nHeader', 'Two\nline')
tree = Treeview(parent, columns=col_list[1:])
ix = -1
for col in col_list:
ix += 1
tree.heading(f'#{ix}', text=col)
The fix
col_list = ('Name\n\n', 'Three\nLine\nHeader', 'Two\nline')
or, if you want to make it look prettier
col_list = ('\nName\n', 'Three\nLine\nHeader', 'Two\nline')
The only problem is I haven't figured out how to centre the heading on a two line header
Edit
The newlines work if it is the top level window but not if it is a dialog. Another way of doing this is to set the style. I've got no idea why this works.
style = ttk.Style()
style.configure('Treeview.Heading', foreground='black')
you can use font size to increase the header height for sometimes;
style = ttk.Style()
style.configure('Treeview.Heading', foreground='black', background='white', font=('Arial',25),)
I need to add an IF statement, FOR and WHILE loop in my form, can someone add some kind of IF statment, FOR and WHILE loop in my code?
from tkinter import * # Ingress all components from Tkinter
mGui = Tk()
mGui.geometry('400x400') # The size of the form window
mGui.title('Registration Form',)
def response():
label3 = Label(text='Thank You!',fg='White', bg='Purple',font='none 16 bold').place(x=140,y=300) # The colours and font style and size used for the response
mlabel = Label(text='Registration Form',fg='White', bg='Purple',font='none 18 bold underline') # The colours and font style and size used for the form title
mlabel.pack()
mlabel2 = Label(text='Forename',fg='White', bg='Purple',font='times 14 bold').place(x=0,y=100) # The colours and font style and size used for the label
mlabel3 = Label(text='Surname',fg='White', bg='Purple',font='times 14 bold').place(x=0,y=150) # The colours and font style and size used for the label
mbutton = Button(text = 'Submit',command = response).place(x=150,y=250) # Location of the the button 'submit' using the x and y axis
mGui.configure(background='Green') # Background colour of the form
mEntry = Entry(bg='White').place(x=100,y=100)
mEntry = Entry(bg='White').place(x=100,y=150)
mGui.mainloop() # The code iterates
Tkinter programs are event-driven, like all GUIs that I know of.
The only place where you can execute your own code is in callbacks or timeouts.
If you want to check the contents of the entry windows, you could do that in at least two ways:
Write a callback function for the Submit button that retrieves the contents of the entry windows and validates them. You could e.g. use a messagebox telling the user that the entries are not valid.
You could also set up the entry windows to validate themselves when a key is pressed. I've used this to e.g. make the text or background of an entry window red if it contains invalid text. You could also put a tip in a Label below the entry windows, like "Both Forename and Surname must at least contain one character."
Note that I am using Python3 and Phoenix.
I would like to display a number (double, but that does not matter now) formatted in some way (again, no matter what that way is) within a rectangle: almost a wx.StaticText but not editable by the user. This is to display some data coming from some hardware, such as a temperature.
Is there such a widget?
I tried with using the default wx.StaticText with a style but I must have done something wrong:
hbox = wx.BoxSizer(wx.HORIZONTAL)
title = wx.StaticText(parent, label=label)
title.SetLabelMarkup("<b>{}</b>".format(label))
hbox.Add(title, border=5)
value = wx.StaticText(parent, label="3.141592", style=wx.BORDER_RAISED)
value.SetWindowStyle(wx.BORDER_SIMPLE)
hbox.Add(value, border=5)
title = wx.StaticText(parent, label="\u2103")
hbox.Add(title, border=5)
Shows this on Linux (Fedora 24, GTK):
Wouldn't using a wx.TextCtrl set to read only do the job?
Temp = wx.TextCtrl(panel1, value="3.141592", style=wx.TE_READONLY)
Temp.SetBackgroundColour('green')
The simplest solution is to just use wxStaticText with a border style (e.g. wxBORDER_SIMPLE, ...). If you don't like the appearance this results in, it's pretty simple to make your own widget drawing whatever border you desire: just create a window, define its wxEVT_PAINT handler and draw the (presumably centered) text in it and a border outside of it.