Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderator: mindphp, ผู้ดูแลกระดาน

rangsan
PHP Hero Member
PHP Hero Member
โพสต์: 199
ลงทะเบียนเมื่อ: 30/04/2018 9:44 am

Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

โพสต์ที่ยังไม่ได้อ่าน โดย rangsan »

ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

ภาพตัวอย่างสิ่งที่ต้องการจะทำ
Selection_088.png
Selection_088.png (27.69 KiB) Viewed 1612 times
จากาพต้องการ Set ค่าให้กับตัว Edit Text เมื่อทำการ Run โปรแกรม ให้มีค่า ตามที่เรากำหนดเลย

เช่น Hostname : localhost
Database : Database
Username : User1
Password : *******
Web Driver Path : Your Path

โค้ดในส่วนของหน้าต่าง Login

โค้ด: เลือกทั้งหมด

class main():
    def __init__(self,master):
        self.master = master
        self.username =  StringVar()
        self.password =  StringVar()
        self.hostname =  StringVar()
        self.database =  StringVar()
        self.pathwebdriver = StringVar()
        self.widgets()

    def selection(self):
        root.filename = filedialog.askopenfile(initialdir = "/",title = "Select file",filetypes = (("files","*.exe"),("all files","*.*")))
        fname = root.filename.name
        self.pathwebdriver.set(fname)

    def login(self):
        link = self.hostname.get() + "/?db=" + self.database.get()
        __builtin__.base_url = link
        __builtin__.chromedriver = self.pathwebdriver.get()
        __builtin__.username = self.username.get()
        __builtin__.pwd = self.password.get()
        __builtin__.db_name = self.database.get()

        suite = unittest.TestLoader().loadTestsFromModule(alloy_all)
        unittest.TextTestRunner(verbosity=2).run(suite)

    def widgets(self):

        self.head = Label(self.master,text = 'LOGIN',font = ('',25),pady = 10)
        self.head.pack()
        self.logf = Frame(self.master,padx =10,pady = 10)
        Label(self.logf,text='Host Name', font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.hostname,bd = 5,font = ('',15)).grid(row=0,column=1)
        Label(self.logf,text = 'Database  ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.database,bd = 5,font = ('',15)).grid(row=1,column=1)
        Label(self.logf,text='Username',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.username,bd = 5,font = ('',15)).grid(row=2,column=1)
        Label(self.logf,text = 'Password   ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15),show = '*').grid(row=3,column=1)
        Label(self.logf,text = 'Path Webdriver ',font = ('',20),pady=5,padx=5 ).grid(sticky = W)
        Entry(self.logf,textvariable = self.pathwebdriver,bd = 5,font = ('',15)).grid(row=4,column=1)
        Button(self.logf,text = ' RUN ',bd = 3 ,font = ('',12),padx=5,pady=5, command=self.login).grid(row=7,column=1)
        Button(self.logf,text = ' Browse ' ,bd = 3 ,font = ('',10),padx=5,pady=5, command=self.selection).grid(row=4,column=2)
        Button(self.logf,text = ' Close ',bd = 3 ,font = ('',12),padx=5,pady=5, command=root.destroy).grid(row=7,column=2)
        self.logf.pack()

if __name__ == '__main__':

    root = Tk()
    root.title('Alloy Login')
    main(root)
    root.mainloop()
อยากทราบวิธีครับ
It’s never too late to start again.
ภาพประจำตัวสมาชิก
nuattawoot
PHP VIP Members
PHP VIP Members
โพสต์: 2561
ลงทะเบียนเมื่อ: 05/06/2017 9:34 am

Re: Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

โพสต์ที่ยังไม่ได้อ่าน โดย nuattawoot »

ลองใช้แบบนี้ ว่าได้ปล่าว

โค้ด: เลือกทั้งหมด

def log(self):
        self.username.set('ใส่ที่ต้องการ')
        self.password.set('ใส่ที่ต้องการ')
     self.logf.pack()
First Bug Love you
รูปภาพ
rangsan
PHP Hero Member
PHP Hero Member
โพสต์: 199
ลงทะเบียนเมื่อ: 30/04/2018 9:44 am

Re: Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

โพสต์ที่ยังไม่ได้อ่าน โดย rangsan »

nuattawoot เขียน:ลองใช้แบบนี้ ว่าได้ปล่าว

โค้ด: เลือกทั้งหมด

def log(self):
        self.username.set('ใส่ที่ต้องการ')
        self.password.set('ใส่ที่ต้องการ')
     self.logf.pack()
ทำได้แล้วครับ ขอบคุณมากครับ
It’s never too late to start again.
Issuresix
PHP Newbie
PHP Newbie
โพสต์: 3
ลงทะเบียนเมื่อ: 19/07/2018 9:55 am

Re: Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

โพสต์ที่ยังไม่ได้อ่าน โดย Issuresix »

ผมก็เคยติดปัญหานี้อยู่เหมือนกันครับ
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 98