会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132450个问题
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Zookeeper 31862楼
Python 全系列/第五阶段:数据库编程/mysql的使用 31863楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 31864楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:基于FastDFS+Nginx+Kinkeditor实现商品新增 31865楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 31866楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/手写服务器项目(旧) 31867楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程技术(旧) 31869楼
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 31870楼

为什么没有出现登录界面,代码没有报错

from tkinter import *
from tkinter import messagebox

class Application(Frame):
    def __init__(self,master=None):
        super().__init__(master)     #super()代表的是父类的定义,而不是父类的对象
        self.master=master
        self.pack()
        self.createWidget()
    def createWidget(self):
        '''创建登陆界面的组件'''
        self.label01=Label(self, text="用户名")
        self.label01.pack()

        #StringVar变量绑定到指点的组件.
        #StringVar变量的值发生变化,组件内容也变化;
        #组件内容发生变化,SringVar变量的值也发生变化
        v1=StringVar()
        self.entry01=Entry(self,textvariable=v1)
        self.entry01.pack()
        v1.set("admin")
        print(v1.get());print(self.entry01.get())



        #创建密码框
        self.label02 = Label(self, text="密码")
        self.label02.pack()


        v2 = StringVar()
        self.entry02 = Entry(self, textvariable=v2,show="*")
        self.entry02.pack()

        Button(self,text="登录",comman=self.login).pack()
    def login(self):
        username=self.entry01.get()
        pwd=self.entry02.get()
        print("去数据库比对用户名和密码")
        print("用户名:"+username)
        print("密码:" + pwd)
        if username=="gaoqi" and pwd=="123456":
             messagebox.showinfo("尚学堂学习系统","登陆成功!欢迎开始学习!")
        else:
              messagebox.showinfo("尚学堂学习系统","登陆失败!重新登录!")
if __name__=='main__':
    root=Tk()
    root.geometry("400x120+200+300")
    app=Application(master=root)
    root.mainloop()


Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 31872楼

"""开发记事本软件的菜单"""

from tkinter.filedialog import *
from tkinter.colorchooser import *


class Application(Frame):

    def __init__(self, master=None):
        super().__init__(master)        # super()代表的是父类的定义,而不是父类对象
        self.master = master
        self.textpad = None             # textpad表示Text文本框对象
        self.pack()
        self.createWidget()

    def createWidget(self):
        # 创建主菜单栏
        menubar = Menu(root)

        # 创建子菜单
        menuFile = Menu(menubar)
        menuEdit = Menu(menubar)
        menuHelp = Menu(menubar)

        # 将子菜单加入主菜单栏
        menubar.add_cascade(label='文件(F)', menu=menuFile)
        menubar.add_cascade(label='编辑(E)', menu=menuEdit)
        menubar.add_cascade(label='帮助(H)', menu=menuHelp)

        # 添加菜单项
        menuFile.add_command(label='新建', accelerator='ctrl+n', command=self.test)
        menuFile.add_command(label='打开', accelerator='ctrl+o', command=self.openfile)
        menuFile.add_command(label='保存', accelerator='ctrl+s', command=self.test)
        menuFile.add_separator()  # 添加分割线
        menuFile.add_command(label='退出', accelerator='ctrl+q', command=self.test)

        # 将主菜单加到根窗口
        root['menu'] = menubar

        # 文本编辑区
        self.textpad = Text(root, width=65, height=30)
        self.textpad.pack()

        # 创建上下菜单
        self.contextMenu = Menu(root)
        self.contextMenu.add_command(label='背景颜色', command=self.test)

        # 右键绑定事件
        root.bind('<Button-3>', self.createContextMenu)

    def openfile(self):
        self.textpad.delete("1.0", "end")  # 把text控件中所有的内容清空
        with askopenfile(title="打开文本文件") as f:
            self.textpad.insert(INSERT, f.read())
            self.filename = f.name
        # try:
        #     # 以utf-8编码打开
        #     with open(askopenfilename()) as f:
        #         self.textpad.insert(INSERT, f.read())
        #         self.filename = f.name
        #         print(f.read())
        # except UnicodeDecodeError:
        #     # 以GBK编码打开
        #     with open(askopenfilename()) as f:
        #         print(f.read())

    def test(self):
        pass

    def createContextMenu(self, event):
        self.contextMenu.post(event.x_root, event.y_root)


if __name__ == '__main__':
    root = Tk()
    root.geometry("450x300+200+300")
    root.title("百战程序员的简易记事本")
    app = Application(master=root)
    root.mainloop()

老师在选择本地文件之后,报这个错误,请问是什么原因?

image.png

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 31874楼

问题:老师我用c3p0数据库连接池用配置文件实现连接时报错了,你看是我这个xml文件建的有问题吗,还是c3p0-0.9.1.2.jar这个版本还需要依赖别的jar包,下面是报的错,最下面是配置文件图片

六月 19, 2020 10:37:26 上午 com.mchange.v2.log.MLog <clinit>

信息: MLog clients using java 1.4+ standard logging.

六月 19, 2020 10:37:27 上午 com.mchange.v2.c3p0.C3P0Registry banner

信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]

六月 19, 2020 10:37:27 上午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager

信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> hellc3p0, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge9eiaa1k63i3np8f2kz|e73f9ac, idleConnectionTestPeriod -> 0, initialPoolSize -> 10, jdbcUrl -> jdbc.mysql://localhost:3306/test, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 100, maxStatements -> 0, maxStatementsPerConnection -> 2, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]

六月 19, 2020 10:37:47 上午 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run

警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1f407bb -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

六月 19, 2020 10:37:47 上午 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run

警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1f407bb -- APPARENT DEADLOCK!!! Complete Status: 

Managed Threads: 3

Active Threads: 3

Active Tasks: 

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4e0ee3ce (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6fe6fc6b (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@7f0acc23 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)

Pending Tasks: 

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@17088d3d

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2e211c81

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@767ca88a

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@5fbe09b2

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@c0c061d

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2a6fc609

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@39440336

Pool thread stack traces:

Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]

java.lang.Thread.sleep(Native Method)

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)

com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]

java.lang.Thread.sleep(Native Method)

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)

com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]

java.lang.Thread.sleep(Native Method)

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)

com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)



六月 19, 2020 10:37:56 上午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run

警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4e0ee3ce -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 

java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getDriver(DriverManager.java:315)

at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)

at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


六月 19, 2020 10:37:56 上午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run

警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@7f0acc23 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 

java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getDriver(DriverManager.java:315)

at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)

at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


六月 19, 2020 10:37:56 上午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run

警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6fe6fc6b -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 

java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getDriver(DriverManager.java:315)

at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)

at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)



java.sql.SQLException: Connections could not be acquired from the underlying database!


at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)

at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)

at com.bjsxt7.connection.C3P0Test.testGetConnection1(C3P0Test.java:31)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)

at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)

at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)

at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.

at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)

at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)

at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)

... 24 more



Process finished with exit code -1

blob.png

JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 31875楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637