|
|
发表于 2019-3-22 12:29:23
|
显示全部楼层
- import tkinter as tk
- from tkinter import ttk
- # import SocketTest
- # import time
- class TcpTool(tk.Tk):
- def __init__(self):
- super().__init__()
- self.modeSelected = tk.StringVar()
- self.canvas = tk.Canvas(self, width=500, height=400)
- self.background = tk.PhotoImage(file=r'1.gif')
- self.dispalyBackground = self.canvas.create_image(250, 0, anchor='n', image=self.background)
- self.combobox = ttk.Combobox(self, textvariable=self.modeSelected)
- self.combobox['value'] = ('', ' TCP-Server', ' TCP-Client', ' UDP')
- self.combobox.current(0)
- # self.mode = tk.Label(text='Communicate Mode')
- # self.displayBackground.pack()
- # self.combobox.place()
- self.combobox.bind("<<ComboboxSelected>>", self.newWindow)
- self.canvas.place(x=0, y=0)
- self.canvas.create_window(100, 80, width=100, height=20, window=self.combobox)
- # self.canvas.create_window(150,50,width=130,height=20,window=self.mode)
- self.title('Communicate Tools')
- self.geometry('500x300')
- self.resizable(False, False)
- self.mainloop()
- def donothing(self):
- pass
- def newWindow(self, event_type):
- if self.combobox.get() == ' TCP-Server':
- mydialog = NewDialog(1)
- elif self.combobox.get() == ' TCP-Client':
- mydialog = NewDialog(2)
- elif self.combobox.get() == ' UDP':
- mydialog = NewDialog(3)
- else:
- return
- self.withdraw()
- self.wait_window(mydialog)
- self.update()
- self.deiconify()
- return
- class NewDialog(tk.Toplevel):
- def __init__(self, event):
- super().__init__()
- self.title('Communicate Tools')
- self.geometry('680x500')
- # self.resizable(False, False)
- self.wm_attributes('-topmost', 1)
- self.frame_top = tk.Frame(self,width=640, height=80, bg='grey')
- self.frame_center_left = tk.Frame(self,width=310, height=250, bg='blue')
- self.frame_center_right = tk.Frame(self,width=310, height=250, bg='yellow')
- self.frame_bottom = tk.Frame(self,width=640, height=100, bg='purple')
- self.localIp = tk.IntVar()
- self.localPort = tk.IntVar()
- self.destinationIp = tk.IntVar()
- self.destinationPort = tk.IntVar()
- self.sendEntry = tk.StringVar()
- self.acceptEntry = tk.StringVar()
- self.click = tk.StringVar()
- self.connectStatus = 0
- self.localIp.set('172.168.155.167')
- self.localPort.set('9000')
- self.destinationIp.set('172.168.155.166')
- self.destinationPort.set('9001')
- self.sendEntry.set('Enter data to send')
- # self.acceptEntry.set('data get from destination ')
- tk.Label(self.frame_top, text='Local IP:', width=10, height=1, font=('Arial', 12)
- ).place(x=20, y=10)
- tk.Label(self.frame_top, text='Local Port:', width=10, height=1, font=('Arial', 12)).place(x=20, y=46)
- tk.Entry(self.frame_top, textvariable=self.localIp, font=('Arial', 13), width=14).place(x=125, y=10)
- tk.Entry(self.frame_top, textvariable=self.localPort, font=('Arial', 13), width=14).place(x=125, y=46)
- tk.Checkbutton(self.frame_top, text='连接', width=8, variable=self.click, font=('幼圆', 11),
- cursor='arrow', selectcolor='red', relief='sunken', justify=tk.CENTER,
- onvalue=1, offvalue=0, command=self.socConnect, indicatoron=False).place(x=560, y=10)
- self.socketStatus = tk.Label(text='', width=9, bg='red').place(x=572, y=56)
- self.remoteAddress = tk.Label(self.frame_top, text='Destination IP', width=15, height=1, font=('Arial', 12))
- self.remotePort = tk.Label(self.frame_top, text='Destination Port', width=15, height=1, font=('Arial', 12))
- self.enter_remoteAddress = tk.Entry(self.frame_top, textvariable=self.destinationIp,
- font=('Arial', 13), width=14)
- self.enter_remotePort = tk.Entry(self.frame_top, textvariable=self.destinationPort,
- font=('Arial', 13), width=14)
- self.remoteAddress.place(x=270, y=10)
- self.remotePort.place(x=270, y=46)
- self.enter_remoteAddress.place(x=420, y=10)
- self.enter_remotePort.place(x=420, y=46)
- tk.Entry(self.frame_center_left, textvariable=self.sendEntry, font=('Arial', 12)).place(x=10, y=220)
- self.sendAreaText = tk.Text(self.frame_center_left, width=33, height=10, font=('Arial', 11))
- self.sendAreaScroll = tk.Scrollbar(self.frame_center_left, orient='vertical', command=self.sendAreaText.yview)
- self.sendAreaText.configure(yscrollcommand=self.sendAreaScroll.set)
- self.send = tk.Label(self.frame_center_left, text='Send Area', width=10, height=1, font=('Arial', 12))
- self.sendAreaScroll.place(x=278, y=100)
- self.sendAreaText.place(x=10, y=35)
- self.send.place(x=107, y=5)
- # tk.Entry(self.frame_center_right, textvariable=self.acceptEntry, font=('Arial', 12)).place(x=10, y=10)
- self.acceptAreaText = tk.Text(self.frame_center_right, width=33, height=10, font=('Arial', 11))
- self.acceptAreaScroll = tk.Scrollbar(self.frame_center_right, orient='vertical', bd=50,
- command=self.acceptAreaText.yview)
- self.acceptAreaText.configure(yscrollcommand=self.acceptAreaScroll.set)
- self.accept = tk.Label(self.frame_center_right, text='Accept Area', width=10, height=1, font=('Arial', 12))
- self.acceptAreaScroll.place(x=278, y=100)
- self.acceptAreaText.place(x=10, y=35)
- self.accept.place(x=107, y=5)
- self.frame_top.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
- self.frame_center_right.grid(row=1, column=0, columnspan=2, padx=10, pady=5)
- self.frame_center_left.grid(row=1, column=2, columnspan=2, padx=5, pady=5)
- self.frame_bottom.grid(row=2, column=0, columnspan=3, padx=10, pady=10)
- self.frame_top.grid_propagate(0)
- self.frame_center_left.grid_propagate(0)
- self.frame_center_right.grid_propagate(0)
- self.frame_bottom.grid_propagate(0)
- self.mainloop()
- def socConnect(self):
- pass
- if __name__ == '__main__':
- L = TcpTool()
复制代码
你都没有把你的frame放置到窗口里 |
|