How to use tkinter (or alternatives) in my MATLAB program ?
10 views (last 30 days)
Show older comments
Md Shahidul Islam
on 1 Aug 2021
Commented: Md Shahidul Islam
on 3 Aug 2021
This is my code below:
function inputbox(self)
self.master = Tk();
self.master.title("Camera Calibration");
label = "What do you want to do?";
text1 = "Calibrate working plane in camera coordinate system";
text2 = "Calibrate camera in robot flange coordinate system";
text3 = "Calculate the robot coordinaes of a point (pixel) in your image";
text4 = "Calculate calibration matrix for pixel to mm (only if camera || work plane)";
text5 = "Calculate an undistorted pixel";
%self.var1, self.var2, self.var3, self.var4, self.var5 = (IntVar() for i = range(5)end)
self.var1=m.Var();
Label(self.master, text=label).grid(row=0, sticky=W);
Checkbutton(self.master, text=text1, variable=self.var1).grid(row=1, sticky=W);
Checkbutton(self.master, text=text2,command=self.var_states, variable=self.var2).grid(row=2, sticky=W);
Checkbutton(self.master, text=text3, command=self.var_states, variable=self.var3).grid(row=3, sticky=W);
Checkbutton(self.master, text=text4, command=self.var_states, variable=self.var4).grid(row=4, sticky=W);
Checkbutton(self.master, text=text5, command=self.var_states, variable=self.var5).grid(row=5, sticky=W);
Button(self.master, text='Start', command=self.main).grid(row=6, sticky=W, pady=4);
Button(self.master, text='Quit', command=self.master.quit).grid(row=7, sticky=W, pady=4);
self.master.mainloop();
end
function inputbox2(self)
self.master2 = Tk();
self.master2.title("Pixel to robot coordinates");
label = "Insert the pixel coordinates and the number of the image position";
text1 = "x / column: ";
text2 = "y / row: ";
text3 = "Number of image position: ";
Label(self.master2, text=label).grid(row=0, sticky=W);
Label(self.master2, text=text1).grid(row=1, sticky=W);
Label(self.master2, text=text2).grid(row=2, sticky=W);
Label(self.master2, text=text3).grid(row=3, sticky=W)
self.e1 = Entry(self.master2);
self.e1.grid(row=1, column=1);
self.e2 = Entry(self.master2);
self.e2.grid(row=2, column=1);
self.e3 = Entry(self.master2);
self.e3.grid(row=3, column=1);
Button(self.master2, text='Accept values', command=self.pixel2robot).grid(row=4, sticky=W, pady=4);
Button(self.master2, text='Quit', command=self.master2.destroy).grid(row=5, sticky=W, pady=4);
self.master2.mainloop();
end
function inputbox3(self)
self.master3 = Tk();
self.master3.title("Undistort Pixel");
label = "Insert the pixel coordinates and the number of the image position";
text1 = "x / column: ";
text2 = "y / row: ";
text3 = "Number of image position: ";
Label(self.master3, text=label).grid(row=0, sticky=W);
Label(self.master3, text=text1).grid(row=1, sticky=W);
Label(self.master3, text=text2).grid(row=2, sticky=W);
Label(self.master3, text=text3).grid(row=3, sticky=W)
self.e11 = Entry(self.master3);
self.e11.grid(row=1, column=1);
self.e22 = Entry(self.master3);
self.e22.grid(row=2, column=1);
self.e33 = Entry(self.master3);
self.e33.grid(row=3, column=1);
Button(self.master3, text='Accept values', command=self.undistort_pixel).grid(row=4, sticky=W, pady=4);
Button(self.master3, text='Quit', command=self.master3.destroy).grid(row=5, sticky=W, pady=4);
self.master3.mainloop()
end
I want to create like this GUI:
I am trying with my code but problem is Tk() function which is not supported in matlab program. Please anyone help me.
0 Comments
Accepted Answer
Dave B
on 1 Aug 2021
Edited: Dave B
on 1 Aug 2021
The easiest way to get started with this is probably using 'App Desiginer' Which you can find by clicking 'Design App' under the Apps tab in the toolbar:
This will help you to create a class for your app, to lay out the controls, and to define callbacks.
Without defining a class for your app, it can be easy to lost track of state, but here's a very simplified approach that creates the controls in a uifigure, and shows a logical vector noting which checkboxes were clicked when you hit Start.
u=uifigure;
g=uigridlayout(u);
g.ColumnWidth={'1x'};
label = "What do you want to do?";
text1 = "Calibrate working plane in camera coordinate system";
text2 = "Calibrate camera in robot flange coordinate system";
text3 = "Calculate the robot coordinaes of a point (pixel) in your image";
text4 = "Calculate calibration matrix for pixel to mm (only if camera || work plane)";
text5 = "Calculate an undistorted pixel";
uilabel(g,'Text',label)
c1=uicheckbox(g,'Text',text1);
c2=uicheckbox(g,'Text',text2);
c3=uicheckbox(g,'Text',text3);
c4=uicheckbox(g,'Text',text4);
c5=uicheckbox(g,'Text',text5);
getchk=@()cell2mat(get([c1 c2 c3 c4 c5],'Value'))';
uibutton(g,'Text','Start','ButtonPushedFcn',@(~,~)disp(getchk()))
uibutton(g,'Text','Quit','ButtonPushedFcn',@(~,~)close(u))
Again, for any more interesting behavior on clicking start I'd recommend trying App Designer, or at least putting this all in a function, and making the 'ButtonPushedFcn' a not-inline function. This was just a quick demo so you could see what it looks like at a high level!
Some Helpful Links
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!