Skip to content

Commit 619f3c4

Browse files
committed
update
1 parent 9ab8c76 commit 619f3c4

File tree

2 files changed

+116
-125
lines changed

2 files changed

+116
-125
lines changed

MQTTClient.py

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
from tkinter import messagebox
1717
from tkinter.font import Font
1818

19+
import about
1920
import new_connect
2021
import new_topic
2122
import subscriber
22-
import about
23-
2423
from 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"

new_connect.py

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,80 +23,69 @@ def __init__(self, main_window, font_size):
2323
self.main_window = main_window
2424
self.title("MQTT Client New Connect")
2525

26-
row = 0
27-
column = 0
26+
ipadding = {'ipadx': 10, 'ipady': 10}
2827

29-
self.label_name = tk.Label(self, text="Name",
30-
font=font_size)
31-
self.label_name.grid(row=row, column=column)
32-
column += 1
33-
self.entry_name_text = tk.StringVar(self)
34-
self.entry_name = tk.Entry(self, font=font_size,
35-
textvariable=self.entry_name_text)
36-
self.entry_name.grid(row=row, column=column)
28+
frame = tk.Frame()
29+
frame.pack()
30+
31+
self.label_name = tk.Label(frame, text="Name",
32+
font=font_size)
33+
self.label_name.pack(**ipadding, fill=tk.X)
3734

38-
row += 1
39-
column = 0
35+
self.entry_name_text = tk.StringVar(frame)
36+
self.entry_name = tk.Entry(frame, font=font_size,
37+
textvariable=self.entry_name_text)
38+
self.entry_name.pack(**ipadding, fill=tk.X)
4039

41-
self.label_broker = tk.Label(self, text="Broker",
40+
self.label_broker = tk.Label(frame, text="Broker",
4241
font=font_size)
43-
self.label_broker.grid(row=row, column=column)
44-
column += 1
45-
self.entry_broker_text = tk.StringVar(self)
46-
self.entry_broker = tk.Entry(self, font=font_size,
47-
textvariable=self.entry_broker_text)
48-
self.entry_broker.grid(row=row, column=column)
42+
self.label_broker.pack(**ipadding, fill=tk.X)
4943

50-
row += 1
51-
column = 0
44+
self.entry_broker_text = tk.StringVar(frame)
45+
self.entry_broker = tk.Entry(frame, font=font_size,
46+
textvariable=self.entry_broker_text)
47+
self.entry_broker.pack(**ipadding, fill=tk.X)
5248

53-
self.label_port = tk.Label(self, text="Port",
49+
self.label_port = tk.Label(frame, text="Port",
5450
font=font_size)
55-
self.label_port.grid(row=row, column=column)
56-
column += 1
57-
self.entry_port_text = tk.StringVar(self)
58-
self.entry_port = tk.Entry(self, font=font_size,
59-
textvariable=self.entry_port_text)
60-
self.entry_port.grid(row=row, column=column)
51+
self.label_port.pack(**ipadding, fill=tk.X)
6152

62-
row += 1
63-
column = 0
53+
self.entry_port_text = tk.StringVar(frame)
54+
self.entry_port = tk.Entry(frame, font=font_size,
55+
textvariable=self.entry_port_text)
56+
self.entry_port.pack(**ipadding, fill=tk.X)
6457

65-
self.label_username = tk.Label(self,
58+
self.label_username = tk.Label(frame,
6659
text="Username", font=font_size)
67-
self.label_username.grid(row=row, column=column)
68-
column += 1
69-
self.entry_username_text = tk.StringVar(self)
70-
self.entry_username = tk.Entry(self, font=font_size,
71-
textvariable=self.entry_username_text)
72-
self.entry_username.grid(row=row, column=column)
60+
self.label_username.pack(**ipadding, fill=tk.X)
7361

74-
row += 1
75-
column = 0
62+
self.entry_username_text = tk.StringVar(frame)
63+
self.entry_username = tk.Entry(frame, font=font_size,
64+
textvariable=self.entry_username_text)
65+
self.entry_username.pack(**ipadding, fill=tk.X)
7666

77-
self.label_password = tk.Label(self,
67+
self.label_password = tk.Label(frame,
7868
text="Password", font=font_size)
79-
self.label_password.grid(row=row, column=column)
80-
column += 1
81-
self.entry_password_text = tk.StringVar(self)
82-
self.entry_password = tk.Entry(self, font=font_size,
69+
self.label_password.pack(**ipadding, fill=tk.X)
70+
71+
self.entry_password_text = tk.StringVar(frame)
72+
self.entry_password = tk.Entry(frame, font=font_size,
8373
textvariable=self.entry_password_text)
84-
self.entry_password.grid(row=row, column=column)
74+
self.entry_password.pack(**ipadding, fill=tk.X)
8575

86-
row += 1
87-
column = 0
88-
self.button_cancel = tk.Button(self, text="Cancel",
76+
self.button_cancel = tk.Button(frame, text="Cancel",
8977
font=font_size,
9078
command=self.cancel)
91-
self.button_cancel.grid(row=row, column=column, padx=50, pady=50)
92-
column += 1
93-
self.button_save = tk.Button(self, text="Save",
79+
self.button_cancel.pack(**ipadding, fill=tk.X)
80+
81+
self.button_save = tk.Button(frame, text="Save",
9482
font=font_size,
9583
command=self.save_config)
96-
self.button_save.grid(row=row, column=column, padx=50, pady=50)
84+
self.button_save.pack(**ipadding, fill=tk.X)
9785

9886
def save_config(self):
99-
ConfigFile().create_file(self.entry_name_text.get(), self.entry_broker_text.get(),
87+
ConfigFile().create_file(self.entry_name_text.get(),
88+
self.entry_broker_text.get(),
10089
self.entry_port_text.get(),
10190
self.entry_username_text.get(),
10291
self.entry_password_text.get())

0 commit comments

Comments
 (0)