I am designing a gui with Tkinter and specific buttons are misbehaving. The main app window includes a button to connect to a machine. The button command works fine, as the connection is successful, but the button does not change relief or color when clicked. If I click out of the app (or create a new window via one of the buttons inside the app), then click back to the main window, the button looks exactly as intended. It is only on startup that the button decides to be lazy.
Once the machine is connected, it brings up more buttons that look and operate correctly, it is only the first button that is a problem. Below are some pictures of the buttons and how they look before and after connecting.
If it helps, I am using OSX 10.10 with updated Python 3.6.5(64-bit for OSX 10.6+ 10.9+),, as well as ActiveTcl version 8.5.18.0.
The following code brings up a test button with the same problem.
import tkinter as tk
if __name__ == '__main__':
root = tk.Tk()
root.title('Button Test')
button = tk.Button(root, text = 'test me', padx= '20', pady = '20')
button.grid()
root.mainloop()
EDIT: I have searched around and found that some people fixed issues similar to this by updating Python/Tcl packages, but my issue seems to be persistent.
EDIT2: I tried changing the type from tk.Button() to tk.ttk.Button() and this seems to fix the visual bug, but it draws a grey border around the new button due to the default "style" option. That is a separate issue however and others have asked how to fix it on here.
答案 0 :(得分:1)
答案 1 :(得分:0)
我在这里看到几个错别字。
变化:
import tkinter as tk
if __name__ = '__main__': # needs to be == not =.
root = tk.Tk()
root.title('Button Test')
# test= should be text=. remove command if you are not using it.
# typo in padx. padx '20; should be padx='20'
button = tk.Button(root, test = 'test me', command = None, padx '20;, pady = '20')
button.grid()
root.mainloop()
对此:
import tkinter as tk
if __name__ == '__main__':
root = tk.Tk()
root.title('Button Test')
button = tk.Button(root, text='test me', padx='20', pady='20')
button.grid()
root.mainloop()