1616from tkinter import messagebox
1717from tkinter .font import Font
1818
19+ import about
1920import new_connect
2021import new_topic
2122import subscriber
22- import about
23-
2423from config_file import ConfigFile
2524
2625
@@ -34,21 +33,23 @@ def __init__(self):
3433 # self.rowconfigure(0, weight=1)
3534 # self.columnconfigure(0, weight=1)
3635
36+ ipadding = {'ipadx' : 10 , 'ipady' : 10 }
37+
38+ frame = tk .Frame (self )
39+ frame .pack (fill = tk .BOTH , expand = True )
40+
3741 font_size = 14
3842 self .text_font = Font (size = font_size )
3943
4044 self .msg_filter = False
41- row = 0
42- column = 0
4345
44- self .label_broker = tk .Label (self , text = "Broker" , font = font_size )
45- self .label_broker .grid (row = row , column = column , sticky = tk .W )
46- column += 1
46+ self .label_broker = tk .Label (frame , text = "Broker" , font = font_size )
47+ self .label_broker .pack (ipadx = 20 , ipady = 20 , fill = tk .BOTH , expand = True , side = tk .LEFT )
4748
4849 self .entry_broker_text = tk .StringVar (self )
4950 self .options_list = ConfigFile ().read_sections ()
5051 self .entry_broker_text .set (self .options_list [0 ])
51- self .entry_broker = tk .OptionMenu (self ,
52+ self .entry_broker = tk .OptionMenu (frame ,
5253 self .entry_broker_text ,
5354 * self .options_list )
5455
@@ -57,132 +58,131 @@ def __init__(self):
5758 self .entry_broker .menuname )
5859 menu .config (font = font_size )
5960
60- self .entry_broker .grid ( row = row , column = column )
61+ self .entry_broker .pack ( ipadx = 20 , ipady = 20 , fill = tk . BOTH , expand = True , side = tk . LEFT )
6162
62- column += 1
63-
64- self .button_connect = tk .Button (self ,
63+ self .button_connect = tk .Button (frame ,
6564 text = "Connect" , font = font_size ,
6665 command = self .button_connect )
67- self .button_connect .grid (row = row , column = column )
68-
69- column += 1
66+ self .button_connect .pack (ipadx = 20 , ipady = 20 , fill = tk .BOTH , expand = True , side = tk .LEFT )
7067
71- self .button_disconnect = tk .Button (self ,
68+ self .button_disconnect = tk .Button (frame ,
7269 text = "Disconnect" , font = font_size ,
7370 state = tk .DISABLED ,
7471 command = self .button_disconnect )
75- self .button_disconnect .grid ( row = row , column = column , sticky = tk .W )
72+ self .button_disconnect .pack ( ipadx = 20 , ipady = 20 , fill = tk .BOTH , expand = True , side = tk . LEFT )
7673
77- row += 1
78- column = 0
74+ frame1 = tk . Frame ( self )
75+ frame1 . pack ( fill = tk . BOTH , expand = True )
7976
8077 # publish topic
81- self .label_publish_topic = tk .Label (self , text = "Publish Topic" ,
78+ self .label_publish_topic = tk .Label (frame1 , text = "Publish Topic" ,
8279 font = font_size )
83- self .label_publish_topic .grid (row = row , column = column , sticky = tk .W )
80+ self .label_publish_topic .pack (** ipadding , expand = True , fill = tk .BOTH ,
81+ side = tk .LEFT )
8482
85- column += 1
8683 self .entry_publish_topic_text = tk .StringVar (self )
87- self .entry_publish_topic = tk .Entry (self ,
84+ self .entry_publish_topic = tk .Entry (frame1 ,
8885 textvariable = self .entry_publish_topic_text ,
8986 font = font_size )
90- self .entry_publish_topic .grid (row = row , column = column )
87+ self .entry_publish_topic .pack (** ipadding , expand = True , fill = tk .BOTH ,
88+ side = tk .LEFT )
9189
92- column += 1
93- self .label_publish_msg_topic = tk .Label (self , text = "Publish Message" ,
90+ self .label_publish_msg_topic = tk .Label (frame1 , text = "Publish Message" ,
9491 font = font_size )
95- self .label_publish_msg_topic .grid (row = row , column = column )
92+ self .label_publish_msg_topic .pack (** ipadding , expand = True ,
93+ fill = tk .BOTH , side = tk .LEFT )
9694
97- column += 1
9895 self .entry_publish_topic_msg_text = tk .StringVar (self )
99- self .entry_publish_msg_topic = tk .Entry (self ,
96+ self .entry_publish_msg_topic = tk .Entry (frame1 ,
10097 textvariable = self .entry_publish_topic_msg_text ,
10198 font = font_size )
102- self .entry_publish_msg_topic .grid (row = row , column = column )
99+ self .entry_publish_msg_topic .pack (** ipadding , expand = True ,
100+ fill = tk .BOTH , side = tk .LEFT )
103101
104- column += 1
105- self .button_publish_topic = tk .Button (self ,
102+ self .button_publish_topic = tk .Button (frame1 ,
106103 text = "Publish" , font = font_size ,
107104 command = self .button_publish_topic )
108- self .button_publish_topic .grid (row = row , column = column )
105+ self .button_publish_topic .pack (** ipadding , expand = True , fill = tk .BOTH ,
106+ side = tk .LEFT )
109107
110- row += 1
111- column = 0
108+ frame2 = tk . Frame ( self )
109+ frame2 . pack ( fill = tk . BOTH , expand = True )
112110
113111 # subscribe topic
114- self .label_subscribe_topic = tk .Label (self , text = "Subscribe Topic" ,
112+ self .label_subscribe_topic = tk .Label (frame2 , text = "Subscribe Topic" ,
115113 font = font_size )
116- self .label_subscribe_topic .grid (row = row , column = column , sticky = tk .W )
114+ self .label_subscribe_topic .pack (** ipadding , expand = True , fill = tk .BOTH ,
115+ side = tk .LEFT )
117116
118- column += 1
119117 self .entry_subscribe_topic_text = tk .StringVar (self )
120118 self .options_list = ["-" , ]
121- self .entry_subscribe_topic = tk .OptionMenu (self ,
119+ self .entry_subscribe_topic = tk .OptionMenu (frame2 ,
122120 self .entry_subscribe_topic_text ,
123- * self .options_list , command = self .add_subscribe_topic )
121+ * self .options_list ,
122+ command = self .add_subscribe_topic )
124123 self .entry_subscribe_topic .config (font = font_size )
125124 menu = self .nametowidget (
126125 self .entry_subscribe_topic .menuname )
127126 menu .config (font = font_size )
128127
129- self .entry_subscribe_topic .grid (row = row , column = column )
128+ self .entry_subscribe_topic .pack (** ipadding , expand = True , fill = tk .BOTH ,
129+ side = tk .LEFT )
130130
131- column += 1
132- self .button_subscribe_topic = tk .Button (self ,
131+ self .button_subscribe_topic = tk .Button (frame2 ,
133132 text = "Subscribe" ,
134133 font = font_size ,
135134 state = tk .DISABLED ,
136135 command = self .button_subscribe )
137- self .button_subscribe_topic .grid (row = row , column = column )
136+ self .button_subscribe_topic .pack (** ipadding , expand = True , fill = tk .BOTH ,
137+ side = tk .LEFT )
138138
139- column += 1
140- self .button_add_subscribe_topic = tk .Button (self ,
139+ self .button_add_subscribe_topic = tk .Button (frame2 ,
141140 text = "Add Subscribe Topic" ,
142141 font = font_size ,
143142 state = tk .DISABLED ,
144143 command = self .add_subscribe_topic )
145- self .button_add_subscribe_topic .grid (row = row , column = column )
144+ self .button_add_subscribe_topic .pack (** ipadding , expand = True ,
145+ fill = tk .BOTH , side = tk .LEFT )
146+
147+ frame3 = tk .Frame (self )
148+ frame3 .pack (fill = tk .BOTH , expand = True )
146149
147150 # filter msg
148- row += 1
149- column = 0
150151
151- self .label_msg_filter = tk .Label (self , text = "Filter Message" ,
152+ self .label_msg_filter = tk .Label (frame3 , text = "Filter Message" ,
152153 font = font_size )
153- self .label_msg_filter .grid (row = row , column = column , sticky = tk .W )
154- self .label_msg_filter .grid (row = row , column = column , sticky = tk .W )
155-
156- column += 1
154+ self .label_msg_filter .pack (** ipadding , expand = True , fill = tk .BOTH ,
155+ side = tk .LEFT )
157156
158157 self .entry_msg_filter_text = tk .StringVar (self )
159- self .entry_msg_filter = tk .Entry (self ,
158+ self .entry_msg_filter = tk .Entry (frame3 ,
160159 textvariable = self .entry_msg_filter_text ,
161160 font = font_size )
162- self .entry_msg_filter .grid ( row = row , column = column )
163- column += 1
161+ self .entry_msg_filter .pack ( ** ipadding , expand = True , fill = tk . BOTH ,
162+ side = tk . LEFT )
164163
165- self .button_filter_add = tk .Button (self ,
164+ self .button_filter_add = tk .Button (frame3 ,
166165 text = "Add Filter" , font = font_size ,
167166 state = tk .DISABLED ,
168167 command = self .add_filter )
169- self .button_filter_add .grid ( row = row , column = column )
170- column += 1
168+ self .button_filter_add .pack ( ** ipadding , expand = True , fill = tk . BOTH ,
169+ side = tk . LEFT )
171170
172- self .button_filter_remove = tk .Button (self ,
171+ self .button_filter_remove = tk .Button (frame3 ,
173172 text = "Remove Filter" ,
174173 font = font_size ,
175174 state = tk .DISABLED ,
176175 command = self .remove_filter )
177- self .button_filter_remove .grid (row = row , column = column )
176+ self .button_filter_remove .pack (** ipadding , expand = True , fill = tk .BOTH ,
177+ side = tk .LEFT )
178178
179- row += 1
180- column = 0
179+ frame4 = tk . Frame ( self )
180+ frame4 . pack ( fill = tk . BOTH , expand = True )
181181
182182 # subscribe list
183- self .listbox_message = tk .Text (self , font = font_size , height = 10 )
184- self .listbox_message .grid ( row = row , column = column , columnspan = 6 ,
185- ipadx = 5 , ipady = 5 , padx = 5 , pady = 5 )
183+ self .listbox_message = tk .Text (frame4 , font = font_size , height = 10 )
184+ self .listbox_message .pack ( ** ipadding , expand = True , fill = tk . BOTH ,
185+ side = tk . LEFT )
186186
187187 # menu
188188 menubar = tk .Menu (self )
@@ -203,25 +203,27 @@ def __init__(self):
203203 command = self .about_window )
204204 menubar .add_cascade (label = "Help" , menu = menu_help )
205205
206+ frame5 = tk .Frame (self )
207+ frame5 .pack (fill = tk .BOTH , expand = True )
208+
206209 # status bar
207210 self .connect_status_text = tk .StringVar ()
208211 self .connect_status_text .set ("..." )
209- self .connect_status = tk .Label (self ,
212+ self .connect_status = tk .Label (frame5 ,
210213 textvariable = self .connect_status_text ,
211214 bd = 1 ,
212215 relief = tk .SUNKEN , anchor = tk .W )
213- row += 1
214- column = 0
215216
216- self .connect_status .grid ( row = row , column = column , columnspan = 5 , sticky = tk . W + tk . E )
217+ self .connect_status .pack ( ** ipadding )
217218
218219 self .subscriber = subscriber .Subscriber (self )
219220
220221 def button_connect (self ):
221222 if self .entry_broker_text .get ():
222223 name , broker , port , username , password = ConfigFile ().read_broker (
223224 self .entry_broker_text .get ())
224- if self .subscriber .connect_start (name , broker , port , username , password ):
225+ if self .subscriber .connect_start (name , broker , port , username ,
226+ password ):
225227 self .connect_status_text .set ("Connected" )
226228 self .button_connect ["state" ] = tk .DISABLED
227229 self .button_connect ["text" ] = "Connected"
0 commit comments