使用tkinter

时间:2017-09-09 16:18:38

标签: python-2.7 tkinter

import Tkinter as tk
import tkMessageBox as tkmb

# globals

buttons = {}
root = None   

# Root Window
root = tk.Tk()
root.wm_title('buttons')

# connect button
comButtonFrame = tk.Frame(root)
label = tk.Label(comButtonFrame, text = 'Open Connection')
label.grid(row=0, column=0, sticky=tk.W)
comPortButtonConnect = tk.Button(comButtonFrame, text='Connect', width=10)
buttons['connect']=comPortButtonConnect

# disconnect button
comPortButtonDisconnect = tk.Button(comButtonFrame, text='Disconnect', width=10)
buttons['disconnect'] = comPortButtonDisconnect


# Program device button
comPortButtonProgram = tk.Button(comButtonFrame, text='Program',width=10)
buttons['program'] = comPortButtonProgram


# display button in a grid
comPortButtonConnect.grid(row=1, column=0, sticky=tk.W)
comPortButtonDisconnect.grid(row=2, column=0, sticky=tk.W)
comPortButtonProgram.grid(row=2, column=1, sticky=tk.W)
comButtonFrame.pack(anchor=tk.W, fill=None, side=tk.TOP, pady=30)

w = root.winfo_width() + 600   # width for the Tk root
h = root.winfo_height() + 830 # height for the Tk root

# get screen width and height
ws = root.winfo_screenwidth() # width of the screen
hs = root.winfo_screenheight() # height of the screen

# calculate x and y coordinates for the Tk root window top left corner
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)

# set the dimensions of the window
# and where it is placed
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
# start in fullscreen mode
# root.attributes('-fullscreen', True)
# run GUI
root.mainloop()

我无法让断开连接和程序按钮彼此靠近。有关如何做到这一点的任何建议?这就是它现在的样子。在我发布的代码中,忽略回调。您可以删除该选项以使其运行。它不相关,因为我只想知道如何修复显示器。

enter image description here

0 个答案:

没有答案