[PYTHON] Try to make PC setting change software using TKinter (beginner)

pcname.PNG

Let's make a simple software for studying python!

I will try to make one software with tkinter with enthusiasm. For the time being, software that changes settings on Windows.

The name is "Let's go home"

I started making it with the concept of "I hope it will be convenient to change settings".

It would be great if we could provide people who want to make Windows setting change software with a little helpful information!

What is tkinter?

A standard python GUI library that allows you to implement an old-looking UI.

After investigating, it seems that the UI design is different between tkinter and tkinter.ttk. ttk has a more modern UI.

Furthermore, the development of PySimpleGUI started in 2018, and it seems that the code is short and the GUI can be assembled with a more modern design.

There is a lot of information on NET this time, so let's challenge with tkinter! That's why I started creating it.

What I made

![ouchi.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/969670/ad8f9423-fc30-1c71-835e-e6b2ad7d3548.png)

It's like this. Yup. It's okay to look like an amateur's work lol

For the time being, I implemented the following. ・ PC name change ・ IPv4 change -Automatic logon

What I noticed after making it

It was quite natural, and I knew it a little, but at least let's make something like a design document lol

At first, I was thinking only about "changing the PC name", but the number of functions I want to implement later has increased steadily. ..

I made changes to the UI each time, so this was a hassle for Moretz. No, it's really stupid. Yup. The idea is no good

I started making it with this kind of glue, but the function itself of the above image has come to work properly.

Since Windows has problems with permissions and UAC, it is necessary to suppress the movement and make the change complete.

In addition, process.run, registry writing, input character check and log output implementation, pyramor, exe conversion, module division, etc. are included, and after restarting, the program is automatically started as step2.

It would be nice if we could release free software if we could debug and brush up, but I think it's still a long way off.

But, after all, By making one thing, you can see the flow of one series! I learned a lot.

Implementation of tkinter

Start implementing the GUI with code like this.
class Application(tk.Frame):
    def __init__(self, master):
        super().__init__(master)
        self.pack()
        self.master.geometry("620x630")
        self.master.title("Let's go home")
        nb = ttk.Notebook(width=200, height=200)

The menu bar looks like this.

        #Creating a menu bar
        self.menubar = tk.Menu(master)
        master.configure(menu = self.menubar)
        #File menu
        filemenu = tk.Menu(self.menubar, tearoff = 0)
        self.menubar.add_cascade(label = "File", menu = filemenu)
        #~ Contents
        filemenu.add_command(label = "Read from file(In development)")
        #~ Contents
        filemenu.add_command(label = "Save to file(In development)")
        #separator
        filemenu.add_separator()
        filemenu.add_command(label = "End", command = lambda: master.destroy())

Tab implementation

        #tab
        tab1 = tk.Frame(nb)
        tab2 = tk.Frame(nb)
        tab3 = tk.Frame(nb)
        tab4 = tk.Frame(nb)
        self.textbox1 = tk.Text(tab4)
        self.textbox1.configure(font=("", 14, ""))
        self.textbox1.pack()
        self.textbox1.place(x=150, y=0,width = 460, height = 570)
        tab5 = tk.Frame(nb)

By the way, tab4 implements textbox.

For example, it would be convenient if you could paste parameters from Excel and change the settings, right? What an idea. The implementation itself is not difficult.

You can read it from a CSV file, or decide how to put the data in this area according to the operation!

Setting change command

You can simply implement the command prompt commands in process.run. I just didn't know how to receive the error level.

So if you want to make a judgment, powershell may be better.

This time, I changed the computer name with powershell and judged the return value to judge normal or abnormal.

IP change

This time I implemented it at the command prompt.

Judgment is OK if you get the parameter from the registry and compare it with the changed value. Note that even if you simply type ipconfig, it will not be output when offline.

If you refer to the registry, you can also output interfaces such as "Ethernet" in a list.

Check function

The value is checked by no input or the number of characters, but the IP address format can be easily checked below.
import ipaddress as ipadd
def chk_ipv4(self,ipaddress):
    try:
        ipadd.ip_address(ipaddress)
        return "ok"
    except ValueError:
        return "ng"

Difficulty

Is it just the right level for python beginners? I think.

I myself studied python and made it in about 2 months.

However, I think it is difficult to make it if you do not understand the movement of Windows.

For those who make similar software

You can make it into an exe with pyinstaller, but if you want to use process.run, you should read the following article. It was very helpful. (Thank you.) https://sapporo-president.com/archives/15581

It didn't work when I made it an exe normally.

Recommended Posts

Try to make PC setting change software using TKinter (beginner)
Try using Tkinter
Try using Python's Tkinter
Try setting SSH (Exscript) from the software to the router
Try setting NETCONF (ncclient) from software to the router
Try to make RESTful API with MVC using Flask 1.0.2
I tried to make a stopwatch using tkinter in python
Try to log in to Netflix automatically using python on your PC
Try to make capture software with as high accuracy as possible with python (1)
Try using pynag to configure Nagios
Try to get statistics using e-Stat
Try to make a capture software with as high accuracy as possible with python (2)
Make it easy to check AGL release software using SW360 / SPDX Lite
Try to make a kernel of Jupyter
Try to detect fusion movement using AnyMotion
Setting to change IPython prompt to'>>>' at startup
Try to operate Excel using Python (Xlwings)
Try to make something like C # LINQ
Try to download Youtube videos using Pytube
I tried to make Kana's handwriting recognition Part 3/3 Cooperation with GUI using Tkinter